ubuntu 安装mysql 与远程访问

安装方式

#安装
apt install mysql-server
#运行下面命令,设置安全模式
mysql_secure_installation

#查看安全模式  默认
show VARIABLES like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)

创建用户

create user 'username'@'host' identified by '要设置的密码'
flush privileges;

远程登录时,要给用户的host改为 ‘指定的地址’或者‘%’(任意地址)都可以。

update user set host = '%' where user= 'username'

如果仍然报错

ERROR 2003 (HY000) Can't connect to MySQL server on '192.168.1.8'

可以查看下面的配置

cat /etc/mysql/mysql.conf.d/mysqld.cnf 
#将bind-address=127.0.0.1注释
#bind-address=127.0.0.1
#重启mysql服务
service mysql restart

你可能感兴趣的:(ubuntu 安装mysql 与远程访问)