Ubuntu 18.04 mysql 5.7

# cat /etc/issue
Ubuntu 18.04.5 LTS \n \l
apt-get update
apt install mysql-server-5.7
# netstat -antlp | grep mysql
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      161732/mysqld
# mysql -V
mysql  Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using  EditLine wrapper
cat /etc/mysql/debian.cnf

配置MySQL 设置 root 新的密码

mysql_secure_installation
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
 Please set the password for root here...
 New password: (输入密码)
Re-enter new password: (重复输入)

#3
 By default, a MySQL installation has an anonymous user,
 allowing anyone to log into MySQL without having to have
 a user account created for them...
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
 Normally, root should only be allowed to connect from
 'localhost'. This ensures that someone cannot guess at
 the root password from the network...
 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (我的选项)

#5
 By default, MySQL comes with a database named 'test' that
 anyone can access...
 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
 Reloading the privilege tables will ensure that all changes
 made so far will take effect immediately.
 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
systemctl status mysql.service

如何更改root密码

mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql>flush privileges;
mysql> exit

配置远程访问

  • 修改端口3306
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address = 127.0.0.1

执行授权命令

  • 任何数据库、来自任何主机(%),并使用密码 123456
mysql>grant all ON *.* to root@'%' identified by '123456' with grant option;
 Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)
mysql> exit
systemctl restart mysql.service

参考

  1. Ubuntu18.04 安装MySQL5.7

你可能感兴趣的:(ubuntu,ubuntu,mysql)