之前从没干过这事儿,对linux了解也不是很深。
在此记下操作记录,便以后自用:
1、备份:数据库用户,数据,my.cnf文件
2、停服务
[root@plcdfgs ~]# service mysqld stop
Stopping mysqld: [ OK ]
3、查看安装的mysql数据库
[root@plcdfgs ~]# yum list installed | grep mysql
mysql.x86_64 5.1.73-7.el6 @base
mysql-community-release.noarch
mysql-devel.x86_64 5.1.73-7.el6 @base
mysql-libs.x86_64 5.1.73-7.el6 @base
mysql-server.x86_64 5.1.73-7.el6 @base
4、挨个儿删除(省去部分打印日志)
[root@plcdfgs ~]# yum -y remove mysql.x86_64
[root@plcdfgs ~]# yum -y remove mysql-community-release.noarch
[root@plcdfgs ~]# yum -y remove mysql-devel.x86_64
[root@plcdfgs ~]# yum -y remove mysql-devel.x86_64
[root@plcdfgs ~]# yum -y remove mysql-server.x86_64
5、去污无残留
[root@plcdfgs ~]# find / -name mysql
/var/lib/mysql
/opt/glassfish3/glassfish/domains/domain6/generated/jsp/YNYCRHPT/loader_10125939/com/mysql
[root@plcdfgs ~]# rm -rf /var/lib/mysql
6、再瞅一眼mysql安装包,没有才是正常的
[root@plcdfgs ~]# rpm -qa | grep -i mysql
7、从网上下载资源,但是此处出错了,只有再浏览器中下载这个文件,放在服务器上了,root文件夹下就行,看个人心情。
[root@plcdfgs ~]# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
--2018-04-12 10:56:16-- http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Resolving dev.mysql.com... 137.254.60.11
Connecting to dev.mysql.com|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm [following]
--2018-04-12 10:56:16-- https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Connecting to dev.mysql.com|137.254.60.11|:443... connected.
ERROR: certificate common name 鈥渨ww.mysql.com鈥? doesn鈥檛 match requested host name 鈥渄ev.mysql.com鈥?.
To connect to dev.mysql.com insecurely, use 鈥?--no-check-certificate鈥?.
[root@plcdfgs ~]# wget dev.mysql.com/get/mysql-conmmunity-release-el6-5.noarch.rpm
--2018-04-12 10:57:23-- http://dev.mysql.com/get/mysql-conmmunity-release-el6-5.noarch.rpm
Resolving dev.mysql.com... 137.254.60.11
Connecting to dev.mysql.com|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql-conmmunity-release-el6-5.noarch.rpm [following]
--2018-04-12 10:57:24-- https://dev.mysql.com/get/mysql-conmmunity-release-el6-5.noarch.rpm
Connecting to dev.mysql.com|137.254.60.11|:443... connected.
ERROR: certificate common name 鈥渨ww.mysql.com鈥? doesn鈥檛 match requested host name 鈥渄ev.mysql.com鈥?.
To connect to dev.mysql.com insecurely, use 鈥?--no-check-certificate鈥?.
8、安装这玩意儿
[root@plcdfgs ~]# yum install mysql-community-release-el6-5.noarch.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.sohu.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.sohu.com
* extras: mirrors.sohu.com
* updates: mirrors.sohu.com
Setting up Install Process
Examining mysql-community-release-el6-5.noarch.rpm: mysql-community-release-el6-5.noarch
Marking mysql-community-release-el6-5.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-release.noarch 0:el6-5 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================
Installing:
mysql-community-release noarch el6-5 /mysql-community-release-el6-5.noarch 4.3 k
Transaction Summary
============================================================================================================================================================================================
Install 1 Package(s)
Total size: 4.3 k
Installed size: 4.3 k
Is this ok [y/N]: Y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mysql-community-release-el6-5.noarch 1/1
Verifying : mysql-community-release-el6-5.noarch 1/1
Installed:
mysql-community-release.noarch 0:el6-5
Complete!
9、显示可用仓库
[root@plcdfgs ~]# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community 45
mysql-tools-community MySQL Tools Community 59
mysql56-community MySQL 5.6 Community Server 378
10、显示所有仓库
[root@plcdfgs ~]# yum repolist all | grep mysql
mysql-connectors-community MySQL Connectors Community enabled: 45
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community MySQL Tools Community enabled: 59
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community MySQL 5.6 Community Server enabled: 378
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community-dmr MySQL 5.7 Community Server Dev disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Dev disabled
11、禁用部分仓库
[root@plcdfgs ~]# yum-config-manager --disable mysql55-community
[root@plcdfgs ~]# yum-config-manager --disable mysql56-community
[root@plcdfgs ~]# yum-config-manager --enable mysql57-community-dmr
12、安装
[root@plcdfgs ~]# yum install mysql-community-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.sohu.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.sohu.com
* extras: mirrors.sohu.com
* updates: mirrors.sohu.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.21-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.21-1.el6 for package: mysql-community-server-5.7.21-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.21-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.21-1.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.21-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.21-1.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.21-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================
Installing:
mysql-community-server x86_64 5.7.21-1.el6 mysql57-community-dmr 152 M
Installing for dependencies:
mysql-community-client x86_64 5.7.21-1.el6 mysql57-community-dmr 23 M
mysql-community-common x86_64 5.7.21-1.el6 mysql57-community-dmr 329 k
mysql-community-libs x86_64 5.7.21-1.el6 mysql57-community-dmr 2.1 M
Transaction Summary
Install 4 Package(s)
Total download size: 178 M
Installed size: 883 M
Is this ok [y/N]: Y
Downloading Packages:
(1/4): mysql-community-client-5.7.21-1.el6.x86_64.rpm | 23 MB 00:08
(2/4): mysql-community-common-5.7.21-1.el6.x86_64.rpm | 329 kB 00:00
(3/4): mysql-community-libs-5.7.21-1.el6.x86_64.rpm | 2.1 MB 00:00
(4/4): mysql-community-server-5.7.21-1.el6.x86_64.rpm | 152 MB 00:43
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.3 MB/s | 178 MB 00:53
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID ********
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
Package: mysql-community-release-el6-5.noarch (@/mysql-community-release-el6-5.noarch)
From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mysql-community-common-5.7.21-1.el6.x86_64 1/4
Installing : mysql-community-libs-5.7.21-1.el6.x86_64 2/4
Installing : mysql-community-client-5.7.21-1.el6.x86_64 3/4
Installing : mysql-community-server-5.7.21-1.el6.x86_64 4/4
Verifying : mysql-community-server-5.7.21-1.el6.x86_64 1/4
Verifying : mysql-community-libs-5.7.21-1.el6.x86_64 2/4
Verifying : mysql-community-common-5.7.21-1.el6.x86_64 3/4
Verifying : mysql-community-client-5.7.21-1.el6.x86_64 4/4
Installed:
mysql-community-server.x86_64 0:5.7.21-1.el6
Dependency Installed:
mysql-community-client.x86_64 0:5.7.21-1.el6 mysql-community-common.x86_64 0:5.7.21-1.el6 mysql-community-libs.x86_64 0:5.7.21-1.el6
Complete!
13、查看新增的文件
[root@plcdfgs ~]# ls /etc/yum.repos.d
CentOS-Base.repo CentOS-Media.repo elrepo.repo epel-testing.repo mysql-community.repo.save mysql-community.repo.save.2 mysql-community-source.repo public-yum-ol6.repo.1
CentOS-Debuginfo.repo CentOS-Vault.repo epel.repo mysql-community.repo mysql-community.repo.save.1 mysql-community.repo.save.3 public-yum-ol6.repo virtualbox.repo
14、启动服务
[root@plcdfgs ~]# service mysqld start
Initializing MySQL database: test
[ OK ]
Starting mysqld: [ OK ]
15、设置mysql开机启动
[root@plcdfgs ~]# chkconfig -- list | grep mysqld
[root@plcdfgs ~]# chkconfig mysqld on
16、查看初始密码
[root@plcdfgs ~]# grep "password" /var/log/mysqld.log
2018-04-12T03:09:12.875687Z 1 [Note] A temporary password is generated for root@localhost: 7T4Wveu),Syo
2018-04-12T03:09:34.113830Z 2 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
17、登陆
[root@plcdfgs ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.7.21
18、mysql要求必须修改密码
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
19、修改mysql密码策略,不然还不能设置简单的密码
mysql> set global validate_password_policy = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'localhost' = password('your password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
20、按照备份的my.cnf文件修改my.cnf配置 ,:wq 保存并退出
mysql> vim /etc/my.cnf
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
21、问题:host....not allowed....,将root用户的host设置为都可以连接
mysql> update user set host='%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
22、重启一下
[root@plcdfgs ~]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
23、登陆
[root@plcdfgs ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
24、分配权限
mysql> grant all privileges on *.* to 'root'@'%' identified by 'ur password' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
到最后需要把记录的用户挨个建立,并重新分配好原来的数据库权限,毕竟做事有头有尾嘛。
注:此文比较粗糙,步骤冗余,仅供参考,如安装中途偶尔出现一点小小的插曲,自行百度 。