安装
sudo apt-get install mysql-server mysql-client
启动
service mysql start
停止
service mysql stop
重启
service mysql restart
允许远程连接
- 找到mysql配置文件并修改
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
- 将bind-address=127.0.0.1注释
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
#
# * Fine Tuning
- 登录mysql,运行命令
grant all privileges on *.* to 'root'@'%' identified by 'mysql' with grant option;
flush privileges;
- 重启mysql
创建远程登录用户先删除一下不能用的,也可以不删!
在某些特殊情况下,可能需要自己创建一个远程登录用户才能使用IP连接mysql,废话不说,直接操作:
- 使用root用户进入mysql
mysql -uroot -p
use database mysql;
select user, host form mysql.user;
delete from mysql.user where user="root" and host!="localhost";
创建远程登录用户
create user 'ding'@'%' identified by '111111';
- 授权查操作
grant select on test.* to 'ding'@'%';
- 授权增操作
grant insert on test.* to 'ding'@'%';
- 授权改操作
grant update on test.* to 'ding'@'%';
- 授权删操作
grant delete on test.* to 'ding'@'%';
完成