[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");
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章