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/data4. Add system mysql group and mysql user:
Execute commands: groupadd mysql and useradd -r -g mysql mysql
5. Initialize the database
There are the following tips during initialization:
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. 启动mysqlservice 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;