Install MySQL for Ubuntu

Time:2021-7-29

This article is continuously updated to record the MySQL installation pit encountered

1. Uninstall MySQL

sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor

2. Installation

2.1. Method 1

sudo apt update
//Install mysql5.7
sudo apt install mysql-server -y

2.2. Method 2

dev.mysql.com/downloads/repo/apt/Copy download link

//Download
curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
//Install with dpkg
sudo dpkg -i mysql-apt-config*
//Update your library
sudo apt update
//Install in the first way
sudo apt install mysql-server -y

3. Verify installation status

//View service startup status
sudo systemctl status mysql.service
//Start MySQL service
sudo systemctl start mysql.service

4. Shut down the service and uninstall

sudo systemctl stop mysql.service && sudo systemctl disable mysql.service
#Make sure you back up your databases in case you want to use them later. You can uninstall MySQL by running the following command:
sudo apt purge mysql*
#Clean up dependencies:
sudo apt autoremove

5. Solve the problem that MySQL can log in without password

5.1 check whether there is an empty record (what you find on the Internet is a pit, and the user cannot be empty)

select count(*) from user where user=””;

5.2 delete if there is one, whether there is one or not

delete from user where user=””;
flush privileges; ( (required)

5.3 execute the following commands (I don’t know what he is doing)

update user set plugin = “mysql_native_password”;

5.4 execute the following code

use mysql;
update user set authentication_ String = password ("your password") where user ='root '//( Version without password field, i.e. version < = 5.7) 
Update user set password = password ('your password ') where user ='root'//( Version with password field, version > 5.7) 
update user set plugin="mysql_native_password"; 
flush privileges; 
exit;

6. Remote access

6.1 firewall

//View firewall
//Turn off the firewall turn on the firewall
//1. Check firewall status
systemctl status firewalld
Firewall CMD -- state # view the default firewall status (not running when turned off, running when turned on)
//2. Check whether the firewall is started
systemctl is-enabled firewalld
//3. Turn off the firewall
systemctl stop firewalld
systemctl stop firewalld.service
systemctl status firewalld
//4. Disable the firewall (the firewall service will not be started when the system is started)
systemctl disable firewalld
systemctl disable firewalld.service
systemctl is-enabled firewalld
//Open 3306 ports
/sbin/iptables -I INPUT -p tcp –dport 3306-j ACCEPT

//Ubuntu firewall
//https://www.linuxidc.com/Linux/2016-12/138259.htm
sudo ufw status

6.2. Set remote password

//Set remote password
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678';
//View password policy
SHOW VARIABLES LIKE 'validate_password%';
Modify password policy:
set global validate_password_policy=LOW;
set global validate_password_length=6;
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
//Equivalent to the following
update user set authentication_string=password("12345678") where user = "root";
flush privileges;

7.0 modifying Alibaba cloud security group rules

Security group – security group rules – configure the security group and add MySQL port 3306.
All the above contents are updated whenever there are new problems

8.0 other issues

If 10061 cannot be connected with Navicat, find/etc/mysql/mysql.conf.d/mysqld.cnf
Configuration found

#bind-address        = 127.0.0.1
//Change to
bind-address        = 0.0.0.0

Restart MySQLservice mysql restartperhapssystemctl restart mysql.service

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Programming for two and a half years, like Ctrl (singing, dancing, rap, basketball)

Recommended Today

VBS obtains the operating system and its version number

VBS obtains the operating system and its version number ? 1 2 3 4 5 6 7 8 9 10 11 12 ‘************************************** ‘*by r05e ‘* operating system and its version number ‘************************************** strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _  (“Select * from […]