[Ubuntu] 安裝並設置遠程連接 MySQL

1. 安裝&啓動

# 安裝
sudo apt-get install mysql-server
sudo apt-get install mysql-client
# 啓動
sudo service start mysql

2. 修改配置文件

修改MySQL配置文件, 允許遠程計算機訪問. 打開配置文件

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address = 127.0.0.1 註釋掉, 然後添加一行 bind-address = 0.0.0.0

2. 創建用戶

創建用戶的命令爲

create user "username"@"host" identified by "password";
  • host = localhost 本地登錄用戶
  • host = ip 指定ip登錄用戶
  • host = % 外網登錄用戶

3. 授予用戶訪問數據庫的權限

授予權限的命令爲

grant all privileges on *.* to "username"@"%" identified by "password";

4. 常用相關命令

- 查看現有用戶

select host,user,authentication_string from mysql.user;

- 新建用戶

create user "username"@"host" identified by "password";

- 刪除用戶

drop user "username"@"host";

- 用戶授權

grant privileges on databasename.tablename to "username"@"host";

- 刪除權限

revoke privileges on databasename.tablename from "username"@"host";

- 修改密碼

set password for "user"@"%" = PASSWORD("123456");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章