Ubuntu system installation and configuration of MySQL

1. Install MySQL

1. Install mysql service

sudo apt-get update
sudo apt install mysql-server-5.7

2. mysql version

mysql -V

 3. View the MySQL default account and password

sudo cat /etc/mysql/debian.cnf

2. Configure MySQL

sudo 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 

3. View the status of mysql service

systemctl status mysql.service
 ps -ef|grep mysqld

4. Modify the root account secret authentication method

sudo cat /etc/mysql/debian.cnf

The password is followed by the password

Then enter at the command line:

mysql -u debian-sys-maint -p
  • Enter the above password in the Enter password that appears to enter the mysql command mode
  • Create database, change password

use mysql;

update mysql.user set authentication_string=('password') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password"; 
flush privileges;
quit;

Five, configure remote access to mysql

1. Modify the configuration file, comment out bind-address = 127.0.0.1

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

2. Save and exit, enter mysql

mysql -uroot -p
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;

reboot

sudo service mysql restart

check status

systemctl status mysql.service

6. Delete MySQL

delete mysql:

sudo apt autoremove --purge mysql-server-*
sudo apt remove mysql-server
sudo apt autoremove mysql-server
sudo apt remove mysql-common

Clean up residual data

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

 

Guess you like

Origin blog.csdn.net/Mouer__/article/details/125520447