One, MySQL download
1. Open the official website and select the corresponding MySQL version according to the configuration. Here, the Linux universal version 5.7.32_64 bit version is used as an example
Official website address: https://dev.mysql.com/downloads/mysql/5.6.html#downloads
2、点击“No thanks,just start my download”
Two, MySQL installation
1. Xshell connects to the Linux test server, enters the usr directory with the cd command, and executes the mkdir mysql command to create a mysql folder for storing the downloaded mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz compressed file
cd /usr
mkdir mysql
ls
2. Click the Xftp file transfer button on Xshell, the transfer interface will open, and the local mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz compressed file can be uploaded to the mysql folder just created in the Linux test server in
3. The upload is successful, you can see the newly uploaded mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz compressed file in the right window
4. Execute the cd command to enter the newly created mysql directory, and the ls command to view the successfully uploaded mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz compressed file
cd mysql/
ls
5. Enter the following command to decompress the mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz compressed file to the /usr/local directory
tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
6. Enter the /usr/local directory with the cd command , execute the ls command, and view the decompressed result
cd /usr/local
ls
7. Execute the following command to create a soft link for the mysql installation directory
ln -s mysql-5.7.32-linux-glibc2.12-x86_64 mysql
8. Enter the cd command into the /usr/local/mysql directory, execute the following command to modify the current directory owner to be the newly created mysql user
chown -R mysql:mysql ./
9. Install mysql, the command is as follows:
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
Note: If it appears as shown in the figure below, the installation is successful, and the green arrow is the generated default password . The random password here must be saved first, and it is recommended to copy it.
10. Start the mysql service, the command is as follows:
./support-files/mysql.server start
note:
①When the service is turned on, if the following error appears, it means that the path in the mysql configuration file /etc/my.cnf is incorrect. At this time, execute the following command to enter the mysql configuration file
vi /etc/my.cnf
② Modify the content in the mysql configuration file my.cnf as follows, modify the datadir and socket to the mysql installation directory, add a [client] section for connecting to the mysql database from the command line
[mysqld]
port=3306
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
max_connections=151
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 设置忽略大小写
lower_case_table_names = 1
# 指定编码
character-set-server=utf8
collation-server=utf8_general_ci
# 开启ip绑定
bind-address = 0.0.0.0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#指定客户端连接mysql时的socket通信文件路径
[client]
socket=/usr/local/mysql/mysql.sock
default-character-set=utf8
Note:
When we edit or modify the content of the file, we need to save the edited content, and then exit the editing window. At this time, we can press "ESC" in the upper left corner of the keyboard, and then enter a "colon", that is, ":" (without double quotes), a colon will appear below, waiting for the input command, it is best to enter "wq" to save And exit.
11. After the my.cnf configuration file is modified, re-execute the start service command in the /usr/local/mysql directory. At this time, the error message disappears and the service is successfully started. The command:
./support-files/mysql.server start
12. Put the mysql process into the system process, the command is as follows:
cp support-files/mysql.server /etc/init.d/mysqld
13. In the /usr/local/mysql directory, restart the mysql service, the command is as follows: service mysqld restart
14. Execute the following command to edit the configuration file
vi/etc/profile
15. In the last line of the configuration file, add the following PATH value to configure the mysql environment variable
export PATH=$PATH:/usr/local/mysql/bin
16. After adding the environment variable to save and exit, execute the following command again to recompile the configuration file. So far, MySQL has been successfully installed
source /etc/profile
Three, MySQL login
Enter the following command and use a random password (the random password here is the string of green random passwords copied before), log in to the mysql database, and see the following screen, which means that the login is successful, the command:
mysql -u root -p
Note: When entering the password, the password is hidden and invisible
Four, MySQL modify password
After successfully logging in to mysql, execute the following command to modify the initial garbled password, command:
alter user 'root'@'localhost' identified by '123456';
Five, MySQL forget password operation
When MySQL forgets the password, you can reset it as follows:
1. Execute the following command to stop the mysql service
service mysqld stop
2. Execute the following command to open the mysql configuration file
vi /etc/my.cnf
3. Add a sentence under the [mysqld] tag of the configuration file: skip-grant-tables, then save and exit
4. Execute the following command to restart the mysql service
service mysqld start
5. Execute the following command to enter the mysql database
mysql -u root
6. Use the database
use mysql;
7. Execute the following command to update the new password
update mysql.user set authentication_string=password('123') where user='root';
8. Execute the following command to refresh the permissions
flush privileges;
Six, set up MySQL remote connection
1. Execute the following command to select the database
use mysql;
2. Execute the following command to set up remote connection
update user set user.Host='%' where user.User='root';
3. Execute the following command to view the modified value
select user,host from user;
4. Execute the following command to refresh the permissions
flush privileges;