Linux uses compressed package to install MySql

1. Download the installation package

https://dev.mysql.com/downloads/mysql/

Select the version as needed, I am using 5.6.39


2. Copy the installation package to the /home/mysql directory and decompress it

tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz


* If the installation directory is selected in /usr/local/mysql, it will save some trouble, because some configurations default to /usr/local/mysql. So it's a bad example, hahaha


3. Create the data directory

mkdir data

The final directory structure looks like this

Installation directory: /home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64

Data directory: /home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/data

4.  Add system mysql group and mysql user:

Execute commands: groupadd mysql and useradd -r -g mysql mysql

5.  Initialize the database

./mysql-5.6.39-linux-glibc2.12-x86_64/scripts/mysql_install_db --user=mysql --basedir=/home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64 --datadir=/home/mysql/data

There are the following tips during initialization:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/bin/mysqladmin -u root password ' new-password '
/home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'


You can start the MySQL daemon with:

cd . ; /home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl


New default config file was created as /home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


6.  Add startup service

cp mysql-5.6.39-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysql

* 这里就需要注意第二条提到的目录的问题,因为mysql.server默认的是/usr/local/mysql,如果安装目录不是这个,就需要修改。修改如下:

basedir=/home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64

datadir=/home/mysql/data

7. 启动mysql

service mysql start


8. 登录

./home/mysql/mysql-5.6.39-linux-glibc2.12-x86_64/bin/mysql -u root -p


9. 远程登录失败

在服务器上登录mysql,然后执行以下命令(记得修改为自己的用户/密码)。再次尝试远程登录后成功

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324483313&siteId=291194637