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

Configure MySQL to set a new password for 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

How to change the root password

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

Configure remote access

  • Modify port 3306
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address = 127.0.0.1

Execute authorized commands

  • Any database, from any host (%), with password 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

reference

  1. Install MySQL5.7 on Ubuntu18.04

Guess you like

Origin blog.csdn.net/u010953692/article/details/131856374