1俄周、連上mysql所在機(jī)器
2髓迎、停止數(shù)據(jù)庫(kù)
[root@lin-21-36-24 ~]# /etc/init.d/mysqld stop
Shutting down MySQL....2019-03-21T11:44:27.298768Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
?SUCCESS!?
3峦朗、進(jìn)入無密碼模式
[root@lin-21-36-24 ~]# cd /usr/local/mysql/bin
[root@lin-21-36-24 bin]# sudo su
[root@lin-21-36-24 bin]# ./mysqld_safe --skip-grant-tables &
4、重新開啟一個(gè)終端窗口
5波势、在新開終端窗口配置短命令
[root@lin-21-36-24 ~]# alias mysql=/usr/local/mysql/bin/mysql
6、進(jìn)入mysql命令模式
[root@lin-21-36-24 ~]# mysql
7橄维、進(jìn)入mysql數(shù)據(jù)庫(kù)
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
8尺铣、獲取權(quán)限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
9、重置root用戶密碼
?mysql> update user set authentication_string=password('root') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 2? Changed: 0? Warnings: 1
10争舞、退出mysql模式
mysql> exit
11、停止mysql
[root@lin-21-36-24 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.... SUCCESS!?
12兑障、啟動(dòng)mysql
[root@lin-21-36-24 ~]# service mysqld start
Starting MySQL. SUCCESS!?
PS :如果遇到改完密碼后連接被拒
解決方案:
1流译、在/etc/my.cnf添加配置項(xiàng)
[mysqld]---在這個(gè)下面添加skip-grant-tables
2福澡、停止mysql
/etc/init.d/mysqld stop
3革砸、重啟mysql
service mysqld start
PS如果遇到mysql stop失敗報(bào)[ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
1)查看進(jìn)程被那誰占用然后kill掉ps aux |grep mysql*
[root@lin-19-73-195 ~]# ps aux |grep mysql*
mysql? ? 3221? 0.7? 0.1 1028464 179972 pts/1? Sl+? 10:55? 0:00 mysqld stop
root? ? ? 3268? 0.0? 0.0? 12132? 656 pts/0? ? S+? 10:57? 0:00 grep mysql*
[root@lin-19-73-195 ~]# kill -9 3221
-bash: kill: (3221) - No such process
[root@lin-19-73-195 ~]# ps aux |grep mysql*
root? ? ? 3270? 0.0? 0.0? 12132? 656 pts/0? ? S+? 10:57? 0:00 grep mysql*