mysql安装和完全卸载
时间:2019-03-20 01:56 来源:linux.it.net.cn 作者:IT
######一、安装
1.查看是否已安装mysql
执行命令:yum list installed | grep mysql
提示:如果没有已安装的mysql,可继续执行下面步骤,如果发现有返回结果则翻到后面的卸载,完成卸载后在回来执行安装步骤
[root@dics-no ~]# yum list installed | grep mysql
[root@dics-no ~]#
2.下载yum源文件
提示:根据具体需求选择下载哪个版本的源文件,可到http://repo.mysql.com/查看有哪些版本
执行命令:wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@dics-no ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2018-09-12 16:26:50-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.209.176.104
Connecting to repo.mysql.com (repo.mysql.com)|23.209.176.104|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ?.ysql-community-release-el7-5.noarch.rpm?
100%[=====================================================================================>] 6,140 --.-K/s in 0.002s
2018-09-12 16:26:51 (2.54 MB/s) - ?.ysql-community-release-el7-5.noarch.rpm?.saved [6140/6140]
[root@dics-no ~]#
3.下载安装包
执行命令:rpm -ivh mysql-community-release-el7-5.noarch.rpm
提示:执行完命令后,查看下/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo
[root@dics-no ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-release-el7-5 ################################# [100%]
[root@dics-no ~]#
4.查看是否已经有可安装的mysql包
执行命令:yum repolist all | grep mysql
[root@dics-no ~]# yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 65
mysql-connectors-community-source MySQL Connectors Community - So disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 69
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - So disabled
mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 412
mysql56-community-source MySQL 5.6 Community Server - So disabled
mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Deve disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled
[root@dics-no ~]#
5.安装mysql
执行命令:yum install -y mysql-community-server
[root@dics-no ~]# yum install -y mysql-community-server
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el7 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.41-2.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.6.41-2.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
mysql-community-server x86_64 5.6.41-2.el7 mysql56-community 59 M
Installing for dependencies:
mysql-community-client x86_64 5.6.41-2.el7 mysql56-community 19 M
mysql-community-common x86_64 5.6.41-2.el7 mysql56-community 257 k
mysql-community-libs x86_64 5.6.41-2.el7 mysql56-community 2.0 M
Transaction Summary
===============================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 81 M
Installed size: 351 M
Downloading packages:
(1/4): mysql-community-common-5.6.41-2.el7.x86_64.rpm | 257 kB 00:00:01
(2/4): mysql-community-libs-5.6.41-2.el7.x86_64.rpm | 2.0 MB 00:00:02
(3/4): mysql-community-client-5.6.41-2.el7.x86_64.rpm | 19 MB 00:00:29
(4/4): mysql-community-server-5.6.41-2.el7.x86_64.rpm | 59 MB 00:00:56
-------------------------------------------------------------------------------------------------------------------------------
Total 1.3 MB/s | 81 MB 00:01:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.6.41-2.el7.x86_64 1/4
Installing : mysql-community-libs-5.6.41-2.el7.x86_64 2/4
Installing : mysql-community-client-5.6.41-2.el7.x86_64 3/4
Installing : mysql-community-server-5.6.41-2.el7.x86_64 4/4
Verifying : mysql-community-server-5.6.41-2.el7.x86_64 1/4
Verifying : mysql-community-client-5.6.41-2.el7.x86_64 2/4
Verifying : mysql-community-common-5.6.41-2.el7.x86_64 3/4
Verifying : mysql-community-libs-5.6.41-2.el7.x86_64 4/4
Installed:
mysql-community-server.x86_64 0:5.6.41-2.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.6.41-2.el7 mysql-community-common.x86_64 0:5.6.41-2.el7
mysql-community-libs.x86_64 0:5.6.41-2.el7
Complete!
[root@dics-no ~]#
6.启动mysql
执行命令:service mysqld start
[root@dics-no ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@dics-no ~]#
7.修改root密码
依次执行以下命令:
mysql -u root
use mysql;
update user set password=PASSWORD(“root”) where User=‘root’;
提示:update user set password=PASSWORD(“这里输入root用户密码”) where User=‘root’;
[root@dics-no ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@dics-no ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD("root") where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> exit
Bye
[root@dics-no ~]#
8.查看是否开机自启
执行命令:
chkconfig --list | grep mysqld
chkconfig mysqld on
[root@dics-no ~]# chkconfig --list | grep mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
[root@dics-no ~]# chkconfig mysqld on
Note: Forwarding request to 'systemctl enable mysqld.service'.
[root@dics-no ~]#
8.mysql安全设置
执行命令:mysql_secure_installation
提示:执行命令后会问你一些安全问题,根据实际需要选择y或n
######二、设置root的远程登录(根据需要)
执行命令:mysql -u root -p
然后输入root账号的密码进入mysql后依次执行以下命令
use mysql;
update user set host = ‘%’ where user = ‘root’;
提示:出现ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’ 不予理会
flush privileges;
select host, user from user;
mysql> update user set host = '%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> select host, user from user;
+----------------------+------+
| host | user |
+----------------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| dics-no.01.novalocal | root |
+----------------------+------+
4 rows in set (0.00 sec)
mysql> flush privileges;
######三、卸载
查看是否已安装mysql
执行命令:yum list installed | grep mysql
[root@dics-no ~]# yum list installed | grep mysql
mysql-community-client.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-common.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-libs.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-release.noarch el7-5 installed
mysql-community-server.x86_64 5.6.41-2.el7 @mysql56-community
[root@dics-no ~]#
2.删除已安装的mysql
执行命令:yum -y remove [第一步命令中出现的包名]
[root@dics-no ~]# yum list installed | grep mysql
mysql-community-client.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-common.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-libs.x86_64 5.6.41-2.el7 @mysql56-community
mysql-community-release.noarch el7-5 installed
mysql-community-server.x86_64 5.6.41-2.el7 @mysql56-community
[root@dics-no ~]# yum -y remove mysql-community-client.x86_64
Removed:
mysql-community-client.x86_64 0:5.6.41-2.el7
Dependency Removed:
mysql-community-server.x86_64 0:5.6.41-2.el7
Complete!
[root@dics-no ~]# yum list installed | grep mysql
Removed:
mysql-community-common.x86_64 0:5.6.41-2.el7
Dependency Removed:
mysql-community-libs.x86_64 0:5.6.41-2.el7 postfix.x86_64 2:2.10.1-6.el7
Complete!
[root@dics-no ~]# yum list installed | grep mysql
mysql-community-release.noarch el7-5 installed
[root@dics-no ~]# yum -y remove mysql-community-release.noarch
Removed:
mysql-community-release.noarch 0:el7-5
Complete!
[root@dics-no ~]# yum list installed | grep mysql
[root@dics-no ~]#
注:以上命令实际执行过程的输出比这里展示的要多,关键是要看到Removed和Complete的输出信息,且过程中没有报错。最后使用yum list installed | grep mysql命令查看,没有任何已安装的mysql组件即可!
3. 删除mysql相关文件
执行命令:find / -name mysql
提示:该命令是查找mysql的相关文件
[root@dics-no ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
[root@dics-no ~]#
执行命令:rm -rf [上面命令查出的结果目录]
提示:删除命令执行完之后,可再使用find / -name mysql 确认是否已经全部删除
[root@dics-no ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
[root@dics-no ~]# rm -rf /var/lib/mysql
[root@dics-no ~]# rm -rf /var/lib/mysql/mysql
[root@dics-no ~]# rm -rf /usr/share/mysql
[root@dics-no ~]# find / -name mysql
[root@dics-no ~]#
4.可以回到安装步骤重新安装mysql了。
(责任编辑:IT)
######一、安装 1.查看是否已安装mysql 执行命令:yum list installed | grep mysql 提示:如果没有已安装的mysql,可继续执行下面步骤,如果发现有返回结果则翻到后面的卸载,完成卸载后在回来执行安装步骤 [root@dics-no ~]# yum list installed | grep mysql [root@dics-no ~]# 2.下载yum源文件 提示:根据具体需求选择下载哪个版本的源文件,可到http://repo.mysql.com/查看有哪些版本 执行命令:wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm [root@dics-no ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm --2018-09-12 16:26:50-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 23.209.176.104 Connecting to repo.mysql.com (repo.mysql.com)|23.209.176.104|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 6140 (6.0K) [application/x-redhat-package-manager] Saving to: ?.ysql-community-release-el7-5.noarch.rpm? 100%[=====================================================================================>] 6,140 --.-K/s in 0.002s 2018-09-12 16:26:51 (2.54 MB/s) - ?.ysql-community-release-el7-5.noarch.rpm?.saved [6140/6140] [root@dics-no ~]# 3.下载安装包 执行命令:rpm -ivh mysql-community-release-el7-5.noarch.rpm 提示:执行完命令后,查看下/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo [root@dics-no ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:mysql-community-release-el7-5 ################################# [100%] [root@dics-no ~]# 4.查看是否已经有可安装的mysql包 执行命令:yum repolist all | grep mysql [root@dics-no ~]# yum repolist all | grep mysql mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 65 mysql-connectors-community-source MySQL Connectors Community - So disabled mysql-tools-community/x86_64 MySQL Tools Community enabled: 69 mysql-tools-community-source MySQL Tools Community - Source disabled mysql55-community/x86_64 MySQL 5.5 Community Server disabled mysql55-community-source MySQL 5.5 Community Server - So disabled mysql56-community/x86_64 MySQL 5.6 Community Server enabled: 412 mysql56-community-source MySQL 5.6 Community Server - So disabled mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Deve disabled mysql57-community-dmr-source MySQL 5.7 Community Server Deve disabled [root@dics-no ~]# 5.安装mysql 执行命令:yum install -y mysql-community-server [root@dics-no ~]# yum install -y mysql-community-server Loaded plugins: product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.6.41-2.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.6.41-2.el7 for package: mysql-community-server-5.6.41-2.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.41-2.el7.x86_64 --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.6.41-2.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.41-2.el7.x86_64 ---> Package mysql-community-common.x86_64 0:5.6.41-2.el7 will be installed --> Running transaction check ---> Package mysql-community-libs.x86_64 0:5.6.41-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =============================================================================================================================== Package Arch Version Repository Size =============================================================================================================================== Installing: mysql-community-server x86_64 5.6.41-2.el7 mysql56-community 59 M Installing for dependencies: mysql-community-client x86_64 5.6.41-2.el7 mysql56-community 19 M mysql-community-common x86_64 5.6.41-2.el7 mysql56-community 257 k mysql-community-libs x86_64 5.6.41-2.el7 mysql56-community 2.0 M Transaction Summary =============================================================================================================================== Install 1 Package (+3 Dependent packages) Total download size: 81 M Installed size: 351 M Downloading packages: (1/4): mysql-community-common-5.6.41-2.el7.x86_64.rpm | 257 kB 00:00:01 (2/4): mysql-community-libs-5.6.41-2.el7.x86_64.rpm | 2.0 MB 00:00:02 (3/4): mysql-community-client-5.6.41-2.el7.x86_64.rpm | 19 MB 00:00:29 (4/4): mysql-community-server-5.6.41-2.el7.x86_64.rpm | 59 MB 00:00:56 ------------------------------------------------------------------------------------------------------------------------------- Total 1.3 MB/s | 81 MB 00:01:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : mysql-community-common-5.6.41-2.el7.x86_64 1/4 Installing : mysql-community-libs-5.6.41-2.el7.x86_64 2/4 Installing : mysql-community-client-5.6.41-2.el7.x86_64 3/4 Installing : mysql-community-server-5.6.41-2.el7.x86_64 4/4 Verifying : mysql-community-server-5.6.41-2.el7.x86_64 1/4 Verifying : mysql-community-client-5.6.41-2.el7.x86_64 2/4 Verifying : mysql-community-common-5.6.41-2.el7.x86_64 3/4 Verifying : mysql-community-libs-5.6.41-2.el7.x86_64 4/4 Installed: mysql-community-server.x86_64 0:5.6.41-2.el7 Dependency Installed: mysql-community-client.x86_64 0:5.6.41-2.el7 mysql-community-common.x86_64 0:5.6.41-2.el7 mysql-community-libs.x86_64 0:5.6.41-2.el7 Complete! [root@dics-no ~]# 6.启动mysql 执行命令:service mysqld start [root@dics-no ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@dics-no ~]# 7.修改root密码 依次执行以下命令: mysql -u root use mysql; update user set password=PASSWORD(“root”) where User=‘root’; 提示:update user set password=PASSWORD(“这里输入root用户密码”) where User=‘root’; [root@dics-no ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@dics-no ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.41 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set password=PASSWORD("root") where User='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> exit Bye [root@dics-no ~]# 8.查看是否开机自启 执行命令: chkconfig --list | grep mysqld chkconfig mysqld on [root@dics-no ~]# chkconfig --list | grep mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. [root@dics-no ~]# chkconfig mysqld on Note: Forwarding request to 'systemctl enable mysqld.service'. [root@dics-no ~]# 8.mysql安全设置 执行命令:mysql_secure_installation 提示:执行命令后会问你一些安全问题,根据实际需要选择y或n ######二、设置root的远程登录(根据需要) 执行命令:mysql -u root -p 然后输入root账号的密码进入mysql后依次执行以下命令 use mysql; update user set host = ‘%’ where user = ‘root’; 提示:出现ERROR 1062 (23000): Duplicate entry ‘%-root’ for key ‘PRIMARY’ 不予理会 flush privileges; select host, user from user; mysql> update user set host = '%' where user = 'root'; ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' mysql> select host, user from user; +----------------------+------+ | host | user | +----------------------+------+ | % | root | | 127.0.0.1 | root | | ::1 | root | | dics-no.01.novalocal | root | +----------------------+------+ 4 rows in set (0.00 sec) mysql> flush privileges; ######三、卸载 查看是否已安装mysql 执行命令:yum list installed | grep mysql [root@dics-no ~]# yum list installed | grep mysql mysql-community-client.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-common.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-libs.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-release.noarch el7-5 installed mysql-community-server.x86_64 5.6.41-2.el7 @mysql56-community [root@dics-no ~]# 2.删除已安装的mysql 执行命令:yum -y remove [第一步命令中出现的包名] [root@dics-no ~]# yum list installed | grep mysql mysql-community-client.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-common.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-libs.x86_64 5.6.41-2.el7 @mysql56-community mysql-community-release.noarch el7-5 installed mysql-community-server.x86_64 5.6.41-2.el7 @mysql56-community [root@dics-no ~]# yum -y remove mysql-community-client.x86_64 Removed: mysql-community-client.x86_64 0:5.6.41-2.el7 Dependency Removed: mysql-community-server.x86_64 0:5.6.41-2.el7 Complete! [root@dics-no ~]# yum list installed | grep mysql Removed: mysql-community-common.x86_64 0:5.6.41-2.el7 Dependency Removed: mysql-community-libs.x86_64 0:5.6.41-2.el7 postfix.x86_64 2:2.10.1-6.el7 Complete! [root@dics-no ~]# yum list installed | grep mysql mysql-community-release.noarch el7-5 installed [root@dics-no ~]# yum -y remove mysql-community-release.noarch Removed: mysql-community-release.noarch 0:el7-5 Complete! [root@dics-no ~]# yum list installed | grep mysql [root@dics-no ~]# 注:以上命令实际执行过程的输出比这里展示的要多,关键是要看到Removed和Complete的输出信息,且过程中没有报错。最后使用yum list installed | grep mysql命令查看,没有任何已安装的mysql组件即可! 3. 删除mysql相关文件 执行命令:find / -name mysql 提示:该命令是查找mysql的相关文件 [root@dics-no ~]# find / -name mysql /etc/selinux/targeted/active/modules/100/mysql /var/lib/mysql /var/lib/mysql/mysql /usr/share/mysql [root@dics-no ~]# 执行命令:rm -rf [上面命令查出的结果目录] 提示:删除命令执行完之后,可再使用find / -name mysql 确认是否已经全部删除 [root@dics-no ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql [root@dics-no ~]# rm -rf /var/lib/mysql [root@dics-no ~]# rm -rf /var/lib/mysql/mysql [root@dics-no ~]# rm -rf /usr/share/mysql [root@dics-no ~]# find / -name mysql [root@dics-no ~]# 4.可以回到安装步骤重新安装mysql了。 (责任编辑:IT) |