Password-free login
ssh-copy-id username
Install tmux
yum install tmux
Install mysql
1. First try to install mysql directly
yum install mysql-community-server
If successful, it means that there is no need to configure MySQL rpm source information, and the installation is completed directly
However, if the following error occurs:
Loading mirror speeds from cached hostfile No package mysql-community-server available. Error: No action needed
Indicates that we have not added the source information of the installation package and need to install the MySQL rpm source information
Install MySQL rpm source information
Open the official website address this
According to your system version, select the corresponding installation package, for example, mine is CentOS 7.5, the Linux kernel of this system is Linux 7, so I chose the address in the red box, and so on.
Splice the download address header: http://dev.mysql.com/get/, get the following address
http://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
Use wget + the address just spliced to download the source information of the installation package
wget http://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
rpm installation source information
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
Install
Try to install MySQL again using yum
yum install mysql-community-server
During the installation process, you will be prompted to confirm, just enter y
and press Enter
After the installation is complete, yum will automatically overwrite the built-in mariaDB, so we don’t need to uninstall it manually
Check if the installation is successful
Check to see if the installation was successful
rpm -qa | grep mysql
output:
mysql-community-libs-compat-8.0.33-1.el7.x86_64 mysql-community-icu-data-files-8.0.33-1.el7.x86_64 mysql80-community-release-el7-7.noarch mysql-community-common-8.0.33-1.el7.x86_64 mysql-community-libs-8.0.33-1.el7.x86_64 mysql-community-server-8.0.33-1.el7.x86_64 mysql-community-client-8.0.33-1.el7.x86_64 mysql-community-client-plugins-8.0.33-1.el7.x86_64
The output is similar to the above, indicating that the installation is complete
Check if mariaDB is overwritten
rpm -qa | grep mariadb
The output is empty, indicating that mariaDB has been successfully overwritten.
Mysql is successfully installed here! ! !
MySQL common commands
# start systemctl start mysqld # After the first startup, you can view the mysql initialization password grep 'temporary password' /var/log/mysqld.log # restart systemctl restart mysqld # stop systemctl stop mysqld # View status systemctl status mysqld #boot systemctl enable mysqld systemctl daemon-reload # View process and version information ps -ef | grep mysql or netstat -atp # Log in mysql -u root -p'password content' # view all tables show databases; # enter the database use table name # view all tables show tables # View information about a table desc table name # check select * from table name # delete delete from table name where field=xx # change update table name set field='xxx' where field='xxx';
Login and change password
When we installed, the initial password was not set
So mysql will automatically initialize a password when it starts for the first time
Through the following line of code, we can view the password automatically initialized by mysql:
# After the first startup, you can view the mysql initialization password grep 'temporary password' /var/log/mysqld.log Output (root@localhost: followed by password): 2023-04-21T06:03:27.071550Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r2to%yZ%a)%s
Login
# Log in to mysql, be sure to pay attention: there is no space between -p and 'password' mysql -u root -p'r2to%yZ%a)%s'
Change root password
Note that the default password policy requires: uppercase English + special characters + numbers
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_123';
Some students may think that I can set whatever password I want, and it’s your turn to use mysql to blind BB here?
It is also possible to modify the password verification policy
First, install the password verification plugin
But there is a premise, you still need to modify the first password according to its requirements before you can install the password verification policy plug-in, haha
1. Change the password once according to the requirements of mysql ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_123'; 2. Exit mysql exit 3. Log in to mysql again mysql -u root -p'Root_123' 4. Install the password verification plug-in install plugin validate_password soname 'validate_password.so'; 5. Check whether the plug-in is enabled select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate%'; + ------------------- + ---------------+ | plugin_name | plugin_status | + ------------------- + ---------------+ | validate_password | ACTIVE | + ------------------- + ---------------+ Output such content, indicating successful activation
View the key and value information of the authentication policy
SHOW VARIABLES LIKE 'validate_password%'; For a higher version of mysql, such as mysql 8, the key of the validation strategy is validate_password.xxx + -------------------------------------- + ------- + | Variable_name | Value | + -------------------------------------- + ------- + | validate_password.check_user_name | ON | | validate_password.dictionary_file | | | validate_password. length | 8 | | validate_password. mixed_case_count | 1 | | validate_password. number_count | 1 | | validate_password.policy | MEDIUM | | validate_password. special_char_count | 1 | + -------------------------------------- + ------- + For lower versions of mysql, such as mysql 5.7, the key of the validation strategy is validate_password_xxx + -------------------------------------- + ------- + | Variable_name | Value | + -------------------------------------- + ------- + | validate_password.check_user_name | ON | | validate_password.dictionary_file | | | validate_password. length | 8 | | validate_password. mixed_case_count | 1 | | validate_password. number_count | 1 | | validate_password.policy | MEDIUM | | validate_password. special_char_count | 1 | + -------------------------------------- + ------- +
We modify the password policy and password length
The key of my policy information is in the format of validate_password.xxx
, so set it as follows
Set the password verification strategy to: 0 (only verify the password length) set global validate.password_policy=0; Set the minimum password length = N, for example, set the minimum password length = 6, that is, the password must be set at least 6 characters or more set global validate.password_length=6;
Ok, now the password can be set according to the policy you just configured
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Open root account remote login
# login mysql -u root -p 'password' # If your database is mysql 8 and above # 1. Enter the database use mysql # 2. Modify the user table update user set host='%' where user='root'; # mysql 5.7 and before, just execute this line of code GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION; # Overload authorization table FLUSH PRIVILEGES; # quit exit # restart systemctl restart mysqld
Port open
After actual measurement, using Alibaba Cloud or Tencent Cloud, there is no need to configure iptables
port information on the server
However, port 3306 must be opened in Alibaba Cloud or Tencent Cloud Console – Server – Security Group.
original address