(1) MySQL advanced installation in Linux Environment


1. general

For MySQL binary installation, the advantage is that it can be installed in any path and has good flexibility. One server can install multiple mysql. The disadvantage is that it has been compiled, and its performance is not as good as that of the source code. It is not flexible to customize the compilation parameters. If users do not want to install the simplest but inflexible RPM package or the complex and time-consuming source package, the compiled binary package will be the best choice. Let’s introduce how to install MySQL server under Linux system.

2. preliminary preparation

2.1 download MySQL binary installation package

MySQL official website:https://dev.mysql.com/downloads/mysql/

Because I downloaded mysql-8.0.23-linux-glibc2.12-x86_ 64.tar version. If the latest version is available, download the latest version.

2.2 import MySQL binary installation package

Transfer the installation package to the package directory of the Linux system through the xftp tool:

3.mysql deployment

● extract the MySQL installation package

--Switch to the installation directory
cd /app
--Unzip the XZ compressed file
tar -xvf /app/package/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

● modify MySQL folder name

--Mysql-8.0.23-linux-glibc2.12-x86_ 64 change to MySQL folder name
mv /app/mysql-8.0.23-linux-glibc2.12-x86_64 /app/mysql

● create data directory

--Create a data directory under the MySQL root directory to store data
mkdir /app/mysql/data

● create MySQL user groups and MySQL users

--Create MySQL user group and MySQL user
groupadd mysql
useradd -g mysql mysql

● modify MySQL directory permissions

--Modify MySQL directory permissions
chown -R mysql.mysql /app/mysql/

● initialize the database

--First switch to the MySQL installation directory
cd /app/mysql
--Initialize database
bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data

● configure MySQL

--First switch to mysql Support files directory
cd /app/mysql/support-files
--Create the file my default in mysql/support-files CNF
touch my-default.cnf
--Copy the configuration file to /etc/my CNF
cp -a ./my-default.cnf /etc/my.cnf
--Edit my CNF
vim /etc/my.cnf

My CNF input the following configuration contents:



● configure environment variables

--Edit profile file
vim /etc/profile
--Configuring MySQL environment variables
export PATH
--Make MySQL environment variables effective
source /etc/profile
--Check whether the environment variable is effective
echo $PATH

● start MySQL

cd /app/mysql/bin
systemctl start mysqld
service mysql start

You may encounter the following errors when starting MySQL:
●Failed to start mysqld.service: Unit not found.

Starting MySQL.Logging to ‘/app/mysql/data/dengwu.err’.
… ERROR! The server quit without updating PID file (/app/mysql/data/dengwu.pid).

The solution is as follows:

--MariaDB server needs to be installed
yum install -y mariadb-server
--Then start the MariaDB service
systemctl start mariadb.service
--If necessary, add MariaDB service for startup
systemctl enable mariadb.service

●Job for mariadb.service failed because the control process exited with error code. See “systemctl status mariadb.service” and “journalctl -xe” for details.

The solution is as follows:

chown -R mysql.mysql /app/mysql/

●Starting MySQL… ERROR! The server quit without updating PID file (/app/mysql/data/dengwu.pid).
The solution is as follows:

--View MySQL process
ps -ef|grep mysqld
--Kill MySQL process
Kill -9 MySQL process ID

Then restart MySQL:

4. modify MySQL password

The root user logs in to MySQL for the first time because we do not know the initial password. Generally, we will reset a new password. The specific operations are as follows:

--Edit my CNF
vim /etc/my.cnf

Enter the following command line:


If you forget your password, add:

--Skip password verification (remove the password when it is set)

Then log in to MySQL:

--Login to MySQL
mysql -u root -p

Then enter the command to view the MySQL user group:

--View MySQL user table
select user,host,authentication_string from mysql.user;

Check that the root user does not have the permission to open the remote connection. If not, execute the following command:

--Modify that the root user can connect remotely
update mysql.user set host='%' where user='root';

After the remote connection permission is enabled, change the root user password:

--If the host is localhost, the @ character is followed by localhost, otherwise it is% subject to the host result
--Modify encryption rules
alter user 'root'@'%' identified by 'qwer1234' password expire never;
--Update the user's password
alter user 'root'@'%' identified with mysql_native_password by 'qwer1234';
--Refresh permissions
flush privileges;
--Modify root user password
alter user 'root'@'%' identified by 'qwer1234';

If the firewall is enabled, you need to add the permission to allow MySQL port access. The specific commands are as follows:

--Allow access
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload
--Check whether access permission is enabled
firewall-cmd --permanent --zone=public --query-port=3306/tcp

Then restart MySQL:

--Restart MySQL
service mysql restart;

5. configure MySQL Alibaba Cloud Security Group Policy

Log in to Alibaba cloud – > security group rules – > access rules – > entry direction – > add the following policies manually:

Successfully connected using Navicat:

Install mysql8.0 under Linux X step

Recommended Today

A front-end developer's Vim is the same as an IDE

Here is my new configurationjaywcjlove/vim-webI've been grinding it, and it's basically ready to use. Take it out and cheat the star Install The latest version of Vim 7.4+ uses (brew install macvim) installation, vim version updatebrew install macvim –override-system-vim View configuration locations # Enter vim and enter the following characters :echo $MYVIMRC download vim-web Download […]