centos7 yum安裝mysql5.7並在root密碼忘記的情況下重設密碼


CentOS7的yum源中默認好像是沒有mysql的。為了解決這個問題,我們要先下載mysql的repo源。

1. 下載mysql的repo源

2. 安裝mysql-community-release-el7-5.noarch.rpm包

安裝這個包后,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

3. 安裝mysql

根據步驟安裝就可以了,不過安裝完成后,沒有密碼,需要重置密碼。

4. 重置密碼

修改MySQL的登錄設置: 
# vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存並且退出vi。

重新啟動mysqld 
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

登錄並修改MySQL的root密碼 
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> UPDATE user SET Password = password ( ‘new-password’ ) WHERE User = ‘root’ ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit

將MySQL的登錄設置修改回來 
# vim /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存並且退出vim

重新啟動mysqld 
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

方式二:

# step1:卸載

[root@codecycle ~]# rpm -qa | grep mysql

mysql-5.1.73-3.el6_5.x86_64

mysql-libs-5.1.73-3.el6_5.x86_64

mysql-server-5.1.73-3.el6_5.x86_64

[root@codecycle ~]# rpm -e --nodeps mysql-5.1.73-3.el6_5.x86_64 mysql-libs-5.1.73-3.el6_5.x86_64 mysql-server-5.1.73-3.el6_5.x86_64

 

 

# step2: 下載yum包,導入本地

[root@codecycle ~]# yum localinstall /usr/local/src/mysql-community-release-el6-5.noarch.rpm

 

 

# step3:安裝

[root@codecycle ~]# yum install mysql-community-server

 

 

# step4:啟動

[root@codecycle ~]# service mysqld start

 

 

# step5:開機啟動

[root@codecycle ~]# chkconfig --list | grep mysqld

mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@codecycle ~]# chkconfig mysqld on

 

 

# step6:設置本地登錄密碼

[root@codecycle ~]# mysqladmin -uroot -p password 123456

 

 

# step7:設置遠程登錄密碼

[root@codecycle ~]# mysql -uroot -p123456

mysql> grant all privileges on *.* to root@'%' identified by 'qaz123wsx' with grant option;

mysql> flush privileges;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM