I wrote an article on the installation of mysql under windows before (click here), it is used less under linux, and recently switched to a linux server, the installation of mysql is different from that under windows, only the installation of compressed packages and rpm packages are recorded. similar
1. Download the installation package
This is not much to say, it can be downloaded from the official website or other places.
Then upload it to the server where it needs to be installed.
2. Unzip
In theory, it can be decompressed to any directory, my decompression path is /data/mysql-5.6
1 tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz -C /data/mysql-5.6
3. Create a soft link.
For the convenience of executing the command, it is better to make a connection. Of course, this step can be omitted.
--connection path cd /usr / local --execute ln -s /data/mysql-5.6 mysql
4. Create a user group for mysql
The -s /bin/false parameter specifies that the mysql user only has ownership without login privileges
-- create user group groupadd mysql --create user useradd -r -g mysql -s /bin/false mysql
5. Add permissions to the mysql installation directory
is to assign permissions to the user created above
cd /data/mysql-5.6 chown -R mysql:mysql ./
6. Install mysql
The current path is /data/mysql-5.6.
./mysql_install_db --datadir=/data/mysql-5.6/data --basedir=/data/mysql-5.6 --user=mysql
If there is an error, it will report "/usr/bin/perl: bad interpreter: No such file or directory", you can install the perl script first, the command is as follows:
yum -y install perl perl-devel yum install -y perl-Data-Dumper
After completion, execute the above initialization mysql script. . . .
If it is version 5.7 or later, you can directly execute the command
./bin/mysqld --user=mysql --basedir=/data/mysql-5.6 --datadir=/data/mysql-5.6/data --initialize
After executing it, take a closer look at the command and generate a random password for root. . .
7. Configure mysql
The location of the default configuration file is /etc/my.cnf. When step 6 is executed, a configuration file will be generated by default
vi /etc/my.cnf
[mysqld] datadir=/data/mysql-5.6/data socket=/data/mysql-5.6/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd # specify encoding character-set-server=utf8 collation-server=utf8_general_ci user=mysql [mysqld_safe] log -error=/var/log/mariadb/ mariadb.log #Can be changed to another path, make sure the path exists, and the mysql user group has write permission pid - file =/var/run/mariadb/ mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d #Specify the socket communication file path when the client connects to mysql [client] socket=/usr/local/mysql/mysql.sock default-character-set=utf8
8. Start the service
If there are no errors, the startup is successful
./support-files/mysql.server start
9. Put the mysql process into the system process, the command is as follows:
cp support-files/mysql.server /etc/init.d/mysqld
10. Restart mysql
service mysqld restart
11. Log in
#The first time you log in without a password, just press Enter
./mysql -u root -p
12. Modify the root password
#xxx is your new password /data/mysql-5.6 / bin /mysqladmin -u root password ' xxx '
At this point, the mysql installation phase is complete. .