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)
1~2_Mysql 的配置之密码重置& mysql 登陆