1. Completely uninstall the installed MySQL service
1. Stop the installed MySQL service
# service mysqld stop
2. View installed MySQL services
# rpm -qa | grep mysql
mysql-community-common-5.7.22-1.el6.x86_64
mysql57-community-release-el6-11.noarch
mysql-community-client-5.7.22-1.el6.x86_64
mysql-community-server-5.7.22-1.el6.x86_64
mysql-community-devel-5.7.22-1.el6.x86_64
mysql-community-libs-5.7.22-1.el6.x86_64
3. Uninstall the installed MySQL services one by one
# rpm -e --nodeps mysql-community-common-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql57-community-release-el6-11.noarch
# rpm -e --nodeps mysql-community-client-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-server-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-devel-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-libs-5.7.22-1.el6.x86_64
4. Find and delete the installation directory and files of the installed MySQL service
4.1. Find
# find / -name mysql
/usr/share/mysql
/var/lib/mysql
/var/lib/mysql/mysql
4.2. Delete one by one
# rm -rf /usr/share/mysql/
# rm -rf /var/lib/mysql/
Second, sftp upload file: mysql57-community-release-el6-11.noarch.rpm, the specific upload process can refer to the blog (CI series one: JDK installation and configuration)
3. Install MySQL
1. Move mysql57-community-release-el6-11.noarch.rpm to the installation directory
# mv mysql57-community-release-el6-11.noarch.rpm /usr/local
2. Switch to the installation directory
# cd /usr/local
3. Install rpm
# yum -y install mysql57-community-release-el6-11.noarch.rpm
4. Install MySQL
# yum -y install mysql-server mysql mysql-devel
Fourth, set the login password of the MySQL user root
1. Start MySQL in normal mode and initialize the database
# service mysqld start
2. Stop the mysql service and start MySQL in safe mode
# service mysqld stop
# mysqld_safe --skip-grant-tables&
3. Password-free login in safe mode to set root login password
3.1. Password-free login in safe mode
#输入命令之后,连续点击enter键,无需输入登录密码
# mysql -uroot -p
3.2. Set the login password
> update mysql.user set authentication_string=password('******') where User = 'root' and Host='localhost';
3.3. Refresh permissions to make the password take effect
> flush privileges
3.4. Exit the MySQL client
> quit
4. Restart the MySQL service, reset the password after the normal mode is started, so that MySQL can be operated normally
4.1. Restart the MySQL service
# service mysqld restart
4.2. Log in with the password you just set
# mysql -uroot -p
4.3. Reset password
> set password for 'root'@'localhost' = password('******');
4.4. Refresh permissions to make the password take effect
> flush privileges
4.5. Exit the MySQL client
> quit
Five, set MySQL to start automatically
1. Set MySQL to start automatically at boot
# chkconfig mysqld on
2. Check whether the setting is successful, the success information is as follows
# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Six, set up MySQL remote login
1. Edit the firewall configuration file, add the following line, open port 3306
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
2. Restart the firewall to make the open ports take effect
# service iptables restart
3. Check whether the port is successfully opened
# service iptables status
4. Use the password to log in to MySQL and set up MySQL remote login
# mysql -uroot -p
> update mysql.user set Host = '%' where User = 'root';
5. Refresh permissions to make remote login take effect
> flush privileges
6. Exit the MySQL client
> quit