標籤:mysql 的配置之密碼重設& mysql 登陸
mysql 黙認mysql 是沒有設定密碼的,正常情況下還是應該設定一個密碼。
[[email protected] ~]# mysql -uroot
用quit 退出來
給mysql 設定密碼
[[email protected] ~]# mysqladmin -uroot password ‘zaq12wsx‘
如果我們忘記了mysql 的密碼,怎麼解決呢?
初始化密碼
[[email protected] ~]# vim /etc/my.cnf #編輯my.cnf
skip-grant #加上這一行
重啟mysql ,就可以直接進去了,不需要輸入密碼。
[[email protected] ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
進入後
mysql> use mysql #使用mysql庫
mysql> update user set password=password(‘zaq12wsx‘) where user=‘root‘;
#更新一個表,更改root 使用者的密碼。注意文法。
Query OK, 2 rows affected (0.00 sec) 這一行發生了改變
mysql> select * from user where user=‘root‘\G; #查看可以看到使用者&密碼。
*************************** 1. row ***************************
Host: localhost
User: root
Password: *839E2E02728DFBA36C0389417509643BFCA1F91C
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
——————————————————————————————————————————
更改設定檔
[[email protected] ~]# vim /etc/my.cnf #編輯my.cnf
skip-grant #刪除這一行
重啟 mysql ,再重新進入,就會提示要求輸入密碼才能進入。
重設密碼到此結束。
———————————————————————————————————————————————
mysql 的登陸
[[email protected] ~]# mysql -uroot -pzaq12wsx # 本地登陸
[[email protected] ~]# mysql -uroot -h10.72.4.30 -P3306 -pzaq12wsx
ERROR 1130 (HY000): Host ‘10.72.4.30‘ is not allowed to connect to this MySQL server
[[email protected] ~]# telnet 10.72.4.30 3306 # 測試下是不是連通的
Trying 10.72.4.30...
Connected to 10.72.4.30.
Escape character is ‘^]‘. #連通沒有問題,但是不能聯,因為沒授權
CHost ‘10.72.4.30‘ is not allowed to connect to this MySQL serverConnection closed by foreign host.
進入到mysql
授權語句
mysql> grant all on *.* to ‘root‘@‘10.72.4.30‘ identified by ‘123456‘;
# * 表示所有的庫,第二個* 表示所有表,連一起,所有庫的所有表。
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 11
Current database: *** NONE ***
Query OK, 0 rows affected (0.00 sec) # 授權成功
mysql> use mysql
Database changed
mysql> select * from user where host=‘10.72.4.30‘\G;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 17
Current database: mysql
*************************** 1. row ***************************
Host: 10.72.4.30
User: root
Password: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
_________________________________________________________________________
[[email protected] ~]# mysql -uroot -h10.72.4.30 -P3306 -p123456 # 測試登陸,
mysql> select user(); #查看當前登陸的使用者
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 20
Current database: *** NONE ***
+-----------------+
| user() |
+-----------------+
| [email protected] |
+-----------------+
1 row in set (0.00 sec)
本文出自 “CBO#Boy_Linux之路” 部落格,請務必保留此出處http://20151213start.blog.51cto.com/9472657/1858592
1~2_Mysql 的配置之密碼重設& mysql 登陸