mysql使用者修改登入密碼及開啟遠程登入

來源:互聯網
上載者:User

標籤:

一、修改使用者登入密碼:

mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> quit
Bye
[[email protected] ~]# mysqladmin -uroot -p password --修改使用者密碼
Enter password:
New password:
Confirm new password:

[[email protected] ~]# mysql -uroot -p --以新密碼登入
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.10 sec)


二、開啟使用者遠程登入許可權
--加-h參數遠程登入mysql資料庫提示如下錯誤
C:\Users\Administrator>mysql -uroot -p -h192.168.1.204
Enter password: *****
ERROR 1130 (HY000): Host ‘192.168.1.123‘ is not allowed to connect to this MySQL server
錯誤分析:主機‘192.168.1.123‘不允許串連到mysql資料庫(沒許可權)。

[[email protected] ~]# myslq -uroot -p --本地登入
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
mysql> select user,password,host from user; --查看使用者資訊,的確root帳號只允許本地登入。
+------+-------------------------------------------+-------------+
| user | password | host |
+------+-------------------------------------------+-------------+
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | localhost |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | rhel204.com |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | 127.0.0.1 |
| root | *76C1B58DE0F08B3169E76CEDD6DD814B32A36F78 | ::1 |
+------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)

mysql> grant all privileges on *.* to [email protected]‘%‘ identified by ‘rusky‘; --授權
Query OK, 0 rows affected (0.03 sec)
或:grant all on db1.* to [email protected]‘%‘; --授權使用者username1從任一用戶端遠程登入資料庫db1,並允許對庫db1做所有操作。
"%"表示任何主機都可以遠程登入到該伺服器上訪問。
*.*表示所有庫的所有對象。
如果要限制只有某台機器可以訪問,將%換成相應的IP即可,如:
GRANT ALL PRIVILEGES ON *.* TO [email protected]‘192.168.1.123’; --可省略IDENTIFIED BY ‘密碼‘;或with grant option;

mysql> flush privileges; --重新整理許可權
Query OK, 0 rows affected (0.04 sec)

C:\Users\Administrator>mysql -uroot -p -h192.168.1.204 --root帳號遠程登入
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
……
mysql>

 

三、建立使用者時就限制使用者的許可權:

create user   ‘lxj‘@‘%‘    identified  by ‘123123‘; 

@後面參數指定該使用者在哪個主機上可以登陸,如果是本機使用者可用localhost, 如果想讓該使用者可以從任意遠程主機登陸,可以使用萬用字元%.

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.