Before installation, confirm that there are no other mysql related configuration files remaining
1. View related installations
# rpm -qa | grep -i mysql
MySQL-server-5.6.27-1.el6.x86_64
MySQL-client-5.6.27-1.el6.x86_64
MySQL-devel-5.6.27-1.el6.x86_64
2. For mysql installed in rpm mode, rm all the contents in the installation list
#yum remove mysql mysql-server mysql-client mysql-devel
3. Delete the MySQL database directory (key), otherwise the password will not be updated (default installation, if you customize the installation path and link path ln -s ...... please delete.)
mysql: /usr/lib/mysql
# rm -rf /usr/lib/mysql
5. Empty all directories and files of related mysql and other configurations and settings. If there is, delete it. It must also be considered that other software does not affect it.
# rm -rf /usr/lib/mysql
# rm -rf /usr/share/mysql
# rm —rf /usr/my.cnf
# rm -rf /root/.mysql_sercret
#6. Self-starting services
# chkconfig --list | grep -i mysql
# chkconfig --del mysqld
: Delete here to see your own settings: mysql/mysqld
1. Download the repo source of mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2. Install the mysql-community-release-el7-5.noarch.rpm package
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
After installing this package, you will get two mysql yum repo sources: /etc/yum.repos.d/mysql-community.repo, /etc/yum.repos.d/mysql-community-source.repo
3. Install mysql
sudo yum install mysql-server
You can install it according to the prompts, but there is no password after the installation is complete, you need to reset the password
4. Reset mysql password
mysql -u root
This error may be reported when logging in: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2), the reason is /var/lib/mysql Access rights issues. The following command changes the owner of /var/lib/mysql to the current user:
sudo chown -R root:root /var/lib/mysql
restart mysql service
service mysqld restart
Next, log in to reset your password:
mysql -u root //Enter mysql console directly
mysql > use mysql;
mysql > update user set password=password('123456') where user='root'; #Set root password
mysql > exit;
Exit mysql and then go back in
mysql -u root -p
enter password
The error may appear again, Access denied for user 'root'@'localhost'(using password:NO)
Then use mysql forgot password root password solution
kill ongoing mysql
1. rcmysqld stop or service mysqld stop or kill -TERM mysqld
2. vim /etc/my.conf add skip-grant-tables
3. Command line execution /usr/bin/mysqld_safe --skip-grant-tables &
4. Reset password
mysql -u root -p //Enter mysql console directly
mysql > use mysql;
mysql > update user set password=password('123456') where user='root'; #Set root password
flush privileges;
exit;
5. vim /etc/my.conf 去掉skip-grant-tables
6.数据库就可以用密码登陆进去了