软件下载
- // 下载二进制格式的 MySQL 软件包
- [[email protected] ~]# cd /usr/src/
- [[email protected] src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
- --2018-08-13 23:56:27-- https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
- Resolving downloads.MySQL.com (downloads.MySQL.com)... 137.254.60.14
- Connecting to downloads.MySQL.com (downloads.MySQL.com)|137.254.60.14|:443... connected.
- HTTP request sent, awaiting response... 302 Found
- Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz [following]
- ......
- Saving to: 'mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz'
- 100%[=====================================>] 643,790,848 2.46MB/s in 4m 20s
- 2018-08-14 00:00:50 (2.36 MB/s) - 'mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz'saved [643790848/643790848]
配置用户和组并解压二进制程序至 / usr/local 下
- // 创建用户和组
- [[email protected] src]# groupadd MySQL -r
- [[email protected] src]# useradd -M -s /sbin/nologin -g MySQL MySQL
- // 解压软件至 / usr/local/
- [[email protected] src]# tar xf MySQL-5.7.22-Linux-glibc2.12-x86_64.tar.gz -C /usr/local/
- [[email protected] ~]# ls /usr/local/
- bin games lib libexec sbin src
- etc include lib64 MySQL-5.7.22-Linux-glibc2.12-x86_64 share
- [[email protected] ~]# cd /usr/local/
- [[email protected] local]# ln -sv MySQL-5.7.22-Linux-glibc2.12-x86_64/ MySQL
- 'mysql' -> 'mysql-5.7.22-linux-glibc2.12-x86_64/'
- // 修改目录 / usr/local/MySQL 的属主属组
- [[email protected] ~]# chown -R MySQL.MySQL /usr/local/MySQL
- [[email protected] ~]# ll /usr/local/MySQL -d
lrwxrwxrwx. 1 MySQL MySQL 35 5 月 13 19:25 /usr/local/MySQL -> MySQL-5.7.22-Linux-glibc2.12-x86_64
- // 配置环境变量
- [[email protected] ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH'> /etc/profile.d/MySQL.sh
- [[email protected] ~]# . /etc/profile.d/MySQL.sh
- [[email protected] ~]# echo $PATH
- /usr/local/MySQL/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
创建各实例数据存放的目录
- [[email protected] ~]# mkdir -p /opt/data/{
- 3306,3307
- }
- [[email protected] ~]# chown -R MySQL.MySQL /opt/data/
- [[email protected] ~]# tree /opt/data/
- /opt/data/
├── 3306
└── 3308
2 directories, 0 files
初始化各实例
- // 初始化 3306 实例
- [[email protected] ~]# mysqld --initialize --datadir=/opt/data/3306 --user=MySQL
- 2019-05-13T15:05:04.079178Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
- 2019-05-13T15:05:05.988959Z 0 [Warning] InnoDB: New log files created, LSN=45790
- 2019-05-13T15:05:06.306727Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
- 2019-05-13T15:05:06.465781Z 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: 7e350f20-7590-11e9-bde0-000c29c97322.
- 2019-05-13T15:05:06.467074Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
- 2019-05-13T15:05:06.470472Z 1 [Note] A temporary password is generated for [email protected]: uo4S%!6Q1yv2
- [[email protected] ~]# echo 'uo4S%!6Q1yv2'>pass1
- // 初始化 3307 实例
- [[email protected] ~]# mysqld --initialize --datadir=/opt/data/3307 --user=MySQL
- 2019-05-13T15:06:27.501609Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
- 2019-05-13T15:06:28.917729Z 0 [Warning] InnoDB: New log files created, LSN=45790
- 2019-05-13T15:06:29.203565Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
- 2019-05-13T15:06:29.271498Z 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: af90351c-7590-11e9-8219-000c29c97322.
- 2019-05-13T15:06:29.276044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
- 2019-05-13T15:06:29.279295Z 1 [Note] A temporary password is generated for [email protected]: efpWPw0>N>w&
- [[email protected] ~]# echo 'efpWPw0>N>w&'>pass2
安装 perl
[[email protected] ~]# yum -y install perl
配置配置文件 / etc/my.cnf
- [[email protected] ~]# vi /etc/my.cnf
- [mysqld_multi]
- mysqld = /usr/local/MySQL/bin/mysqld_safe
- mysqladmin = /usr/local/MySQL/bin/mysqladmin
- user = root
- [mysqld3306]
- datadir = /opt/data/3306
- port = 3306
- socket = /tmp/mysql3306.sock
- pid-file = /opt/data/3306/mysql_3306.pid
- log-error=/var/log/3306.log
- [mysqld3307]
- datadir = /opt/data/3307
- port = 3307
- socket = /tmp/mysql3307.sock
- pid-file = /opt/data/3307/mysql_3307.pid
- log-error=/var/log/3307.log
启动各实例
- [[email protected] ~]# mysqld_multi start 3306
- [[email protected] ~]# mysqld_multi start 3307
- [[email protected] ~]# ss -antl
- State Recv-Q Send-Q Local Address:Port Peer Address:Port
- LISTEN 0 128 *:22 *:*
- LISTEN 0 100 127.0.0.1:25 *:*
- LISTEN 0 80 :::3307 :::*
- LISTEN 0 128 :::22 :::*
- LISTEN 0 100 ::1:25 :::*
- LISTEN 0 80 :::3306 :::*
初始化密码
- [[email protected] ~]# ls
- anaconda-ks.cfg pass1 pass2
- [[email protected] ~]# cat pass1
- uo4S%!6Q1yv2
- [email protected] ~]# MySQL -uroot -p'uo4S%!6Q1yv2' -S /tmp/mysql3306.sock
- MySQL: [Warning] Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.7.22
- Copyright (c) 2000, 2018, 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.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MySQL> set password =('ly123');
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('ly123')' at line 1
- MySQL> set password = password('ly123');
- Query OK, 0 rows affected, 1 warning (0.00 sec)
- MySQL> quit
- Bye
来源: http://www.bubuko.com/infodetail-3057695.html