文章目录
1. 下载安装包
MySQL下载地址:http://dev.mysql.com/downloads/mysql/
选择 Linux - Generic,下载mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
2. 创建mysql用户组
sudo groupadd mysql;
sudo useradd -r -g mysql -s /bin/false mysql;
3. 创建安装目录以及数据存储目录
# 安装目录
sudo mkdir /mysql;
# 数据存储目录
sudo mkdir -p /mysqldata/mysql3307;
sudo mkdir -p /mysqldata/mysql3308;
4. 解压安装包
cd /mysql;
sudo tar -zxvf /home/unispace/Downloads/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz;
sudo mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql3307;
5. 修改MySQL目录权限
cd mysql3307;
sudo chown -R mysql:mysql .;
6. 创建配置文件
在mysql3307目录中创建my.cnf,配置文件内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
#
[client]
port = 3307
socket = /mysql/mysql3307/mysqld.sock
[mysqld_safe]
socket = /mysql/mysql3307/mysqld.sock
pid-file = /mysql/mysql3307/mysqld.pid
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /mysql/mysql3307
datadir = /mysqldata/mysql3307
port = 3307
server_id = 11
socket = /mysql/mysql3307/mysqld.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
7. 初始化数据库
sudo bin/mysqld --defaults-file=/mysql/mysql3307/my.cnf --initialize --user=mysql;
结果如下:
2016-07-29T15:38:48.896585Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-29T15:38:48.896672Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-07-29T15:38:48.896682Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-07-29T15:38:50.498675Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-29T15:38:50.890849Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-29T15:38:51.062752Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8c708a13-55a2-11e6-835e-a0481ced538c.
2016-07-29T15:38:51.088854Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-29T15:38:51.090179Z 1 [Note] A temporary password is generated for root@localhost: pJLwjf%q;1t)
其中 pJLwjf%q;1t 为初始密码
8. 加密连接
sudo bin/mysql_ssl_rsa_setup --defaults-file=/mysql/mysql3307/my.cnf;
结果如下:
Generating a 2048 bit RSA private key
.........+++
.......................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
..........+++
..............................................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
................................................+++
........................................+++
writing new private key to 'client-key.pem'
-----
9. 启动MySQL
sudo bin/mysqld_safe --user=mysql &;
10. 登录MySQL
bin/mysql -uroot -p -S /mysql/mysql3307/mysqld.sock
11. 修改密码以及创建远程登录账号
# 修改密码
mysql> SET PASSWORD = PASSWORD('iunispace');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
# 创建账号
mysql> grant all privileges on *.* to 'root'@'%' identified by 'iunispace' with grant option;
重复上面的步骤,可以安装多个mysql
12. 停止MySQL
bin/mysqladmin -uroot -piunispace -S /var/lib/1_mysql/mysqld.sock shutdown