1~2_Mysql 的配置之密碼重設& mysql 登陸

來源:互聯網
上載者:User

標籤: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 登陸

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.