1. Create a group
shell> groupadd mysql
2. Create user
shell> useradd -r -g mysql -s /bin/false mysql
3. Unzip the mysql compressed package to the directory you want to install. When unzipping, you can use -C to specify the target directory to unzip.
shell> tar -zxvf mysql-5.5.58.tar.gz
After decompression, you can use mv to rename, rename to mysql-5.5.58
shell> mv mysql-5.5.58-linux-glibc2.12-x86_64 mysql-5.5.58
4. Change the user and group of the decompressed mysql file to mysql.
shell> chown -R mysql mysql-5.5.58
shell> chgrp -R mysql mysql-5.5.58
5. To initialize the core data of the mysql database, execute the following commands in the mysql-5.5.58 directory.
shell> scripts/mysql_install_db --user=mysql
6. Start the mysql service
shell> bin/mysqld_safe --user=mysql
7. To verify whether the mysql service starts successfully, you can use the following command.
shell> bin/mysqladmin version
If the version information can be output correctly, the installation is successful, such as:
bin/mysqladmin Ver 8.42 Distrib 5.5.58, for linux-glibc2.12 on x86_64
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.58
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 3 min 50 sec
Threads: 1 Questions: 2 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.008
8. Login to mysql
The root user of the initialized mysql has no password, so we can use it mysql -u root
to log in.
shell> bin/mysql -u root
9. Specify a password for the root user
The basic syntax is as follows:
mysql> SET PASSWORD FOR 'root'@'host' = PASSWORD('new_password');
Looking at the mysql.user table we will see the combination of root user and localhost, so we can specify the initial password as follows.
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('elim');
Query OK, 0 rows affected (0.00 sec)
It is also possible to update the password in the mysql.user table directly.
shell> mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('new_password')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
You can also set the root user password through mysqladmin
shell> mysqladmin -u root password "new_password"
shell> mysqladmin -u root -h host_name password "new_password"
After specifying the password, we will no longer be able to log in by logging in without specifying the root user password.
shell> bin/mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Then you can use the password elim we just specified to log in.
shell> bin/mysql -uroot -pelim
10. Install mysql as linux service
Copy mysql.server in the support-files directory to the /etc/init.d directory and name it mysql.
shell> cp support-files/mysql.server /etc/init.d/mysql
Also, you need to make sure that /etc/init.d/mysql has execute permission (usually it comes automatically).
shell> chmod +x /etc/init.d/mysql
Copy a my-xxx.cnf file in the support-files directory to the /etc directory and name it my.cnf
shell> cp support-files/my-medium.cnf /etc/my.cnf
If the base path of mysql is not /usr/local/mysql, you need to specify basedir and datadir under the mysqld block of /etc/my.cnf, such as:
[mysqld]
basedir=/usr/local/mysql-5.5.58
datadir=/usr/local/mysql-5.5.58/data
socket=/var/tmp/mysql.sock
port=3306
user=mysql
Then use systemctl daemon-reload
the reload service information service mysql start
to start the mysql service.