Install MySql on CentOS
Note that root privileges are required
Install version 5.7
– Since MySql is not in the official warehouse of CentOS, you need to use the rmp command:
import the MySQL warehouse key
1, configure the yum warehouse of MySQL
Configure the yum warehouse
update key
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
Install Mysql yum repository
rpm -Uvh http://repo.nysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2. Use yum to install MySQL
yum install mysql
yum -y install mysql-community-server
3. After the installation is complete, start mySQl and configure the startup to start
MySQL. After the installation is complete, it will be automatically configured as a service named: mysqld , so it can be controlled by systemctl
systemctl start mysqld # Start
sytemctl enable mysqld # Boot from start
4. Check the running status of MySQL
systemctl status mysqld
Friendly reminder
1. Obtain the initial password of MySQL root
grep ‘temporary password’ /var/log/mysqld.log
2. Log in to the MySQL database system
implement
mysql -u root -p
Enter the initial password obtained above to log in to the MySQL database
3. Configure MySQL security policy
set global validate_password_policy=LOW; # password security level set password policy LOW, MEDIUM, STRONG
set global validate_password_length=4; # password length
4. Modify root user password
Execute in the MySQL console
ALter USER ‘root’@‘localhost’ IDENTIFIED BY ‘密码’
5. Configure root remote login
By default, the root user is not allowed to log in remotely, only allowed to log in to the MySQL system on the Linux server where MySQL is located.
Authorize root remote login
grant all privileges on . to root@“IP地址” identified by ‘密码’ with grant option;
IP address: the IP address that allows remote login, and % can also be used to represent any computer localhost: only local login is allowed
Password: The password for remote login can be different from the password for local login
6. Refresh permissions
flush privileges ;
Install version 8.0
Note that root authority is required
1. Configure MySQL's yum warehouse
Configure the yum warehouse
update key
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
Install Mysql yum repository
rpm -Uvh http://repo.nysql.com/get/mysql80-community-release-el7-2.noarch.rpm
2. Use yum to install MySQL
yum install mysql
yum -y install mysql-community-server
3. After the installation is complete, start mySQl and configure the startup to start
MySQL. After the installation is complete, it will be automatically configured as a service named: mysqld , so it can be controlled by systemctl
systemctl start mysqld # Start
sytemctl enable mysqld # Boot from start
4. Check the running status of MySQL
systemctl status mysqld
Friendly reminder
1. Obtain the initial password of MySQL root
grep ‘temporary password’ /var/log/mysqld.log
2. Log in to the MySQL database system
implement
mysql -u root -p
Enter the initial password obtained above to log in to the MySQL database
3. Configure MySQL security policy
set global validate_password_policy=0; # password security level setting password policy version 5.7 : LOW, MEDIUM, STRONG
set global validate_password_length=4; # password length
4. Modify root user password
Execute in the MySQL console
Version 5.7
ALter USER 'root'@'localhost' IDENTIFIED by 'password' Version
8.0
ALter USER 'root'@'localhost' IDENTIFIED with mysql_native_password by 'password'
5. Configure root remote login
By default, the root user is not allowed to log in remotely, only allowed to log in to the MySQL system on the Linux server where MySQL is located.
version 5.7Authorize root remote login
grant all privileges on . to root@“IP地址” identified by ‘密码’ with grant option;
IP address: the IP address that allows remote login, and % can also be used to represent any computer localhost: only local login is allowed
Password: The password for remote login can be different from the password for local login
version 8.0
Set up root remote login for the first time and configure the remote password
create user ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘密码’
Subsequent password changes
Alter user ‘root’@‘%’ identified with mysql_native_password BY ‘密码’
6. Refresh permissions
flush privileges ;
Install MySql on Ubuntu
Install 5.7 MySQL on Ubuntu
The installed Ubuntu is the latest version, and the built-in Mysql in this version of the software store is also the latest version 8.0.
If you want to install MySQL 5.7, additional steps are required
(1) Download the apt warehouse file
Download the installation package from the apt repository, the Ubuntu installation package is a .deb file
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
(2) Configure the apt warehouse
Install the repository using the dpkg command
dpkg -i mysql-apt-config_0.8.12-1_all.deb
Select Ubuntu bionic in the pop-up box (the code name of the Ubuntu18.04 system is bionic, select the 18.04 version library for installation) press
Enter
, select MySQL Server & Cluste, press Enter
and select mysql- 5.7
Finally choose ok
(3) Update the information of the apt warehouse
First import the key information of the warehouse
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Update warehouse information
apt update
(4) Check whether the MySQL5.7 warehouse is successfully configured
apt-cache policy mysql-server
(5) Install MySQL 5.7
Use apt to install mysql client and mysql server
apt install -f -y mysql-client=5.7* mysql-community-server=5.7*
(6) Start MySQL
Because MySQL does not automatically add its own services to the systemctl management system
sudo /etc/init.d/mysql start # Start
sudo /etc/init.d/mysql stop # Stop
sudo /etc/init.d/mysql status # View state
service mysql status # View mysql service status
service mysql stop # close mysql service
service mysql start # start mysql
(7) MySQL initialization
Execute the following command This command is a configuration program that comes with MySQL after installation
mysql_secure_installation
You can use the which command to view the path of the built-in program
Whether mysql_secure_installation
enables the password verification plug-in. If you need to enhance the password security, enter Y and press Enter, you don’t need to press Enter directly.
Whether to change the root password, you need to enter Y and press Enter, you don’t need to press Enter directly.
Whether to remove anonymous users, to remove enter Y and press Enter, if not remove Enter
Whether to prohibit the remote login of the root user, prohibit the input of Y and press Enter, and directly press Enter if not prohibited
Whether to remove the built-in test database, remove the input y and press Enter, do not remove directly press Enter
Whether to refresh permissions, refresh input y and press enter, do not refresh directly press enter
Install 8.0 MySQL on Ubuntu
Install Mysql 8.0 version
1. If you have installed version 5.7 before, you need to uninstall the warehouse information
Uninstall MySQL 5.7 version
sudo apt remove -y mysql-client=5.7* mysql-community-server=5.7*
Uninstall the warehouse information of 5.7
sudo dpkg -l | grep mysql | awk ‘{print $2}’ | xarings dpkg -P
2. Update apt warehouse information
apt update
3. Install mysql
sudo apt install -y mysql-server
4. Start mysql
service mysql status # View mysql service status
service mysql stop # close mysql service
service mysql start # start mysqlBecause MySQL does not automatically add its own services to the systemctl management system
sudo /etc/init.d/mysql start # Start
sudo /etc/init.d/mysql stop # Stop
sudo /etc/init.d/mysql status # View state
5 Log in to mysql and change the root password
sudo mysql
login password for linux This is root login, you can check the login name by selecting current_user();#Modify root password mysql 8.0
alter user 'root'@'localhost' identified with mysql_native_password by 'password' # The password here is in plain text and does not require MD5 encryptionmysql 5.7
alter user 'root'@'localhost' identified by 'password' # clear text password, no password() required
6. Exit mysql
exit
7. The initialization of MySQL is the same as that of mysql 5.7
Execute the following command This command is a configuration program that comes with MySQL after installation
mysql_secure_installation
You can use the which command to view the path of the built-in program
Remove the access to the test database, whether it is abnormal anonymous access,
whether it is abnormal root remote login