源码和多实例安装mysql5.7
这里使用两台centos7虚拟机俩进行安装一、源码安装mysql(网址来源Index of /mysql/Downloads/MySQL-5.7/)1、网络下包wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-boost-5.7.37.tar.gz2、安装开发工具和开发包yum install make gcc gcc-c
·
这里使用两台centos7虚拟机俩进行安装
目录
一、源码安装mysql
(网址来源Index of /mysql/Downloads/MySQL-5.7/)
1、网络下包
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-boost-5.7.37.tar.gz
2、安装开发工具和开发包
yum install make gcc gcc-c++ cmake bison-devel ncurses-devel -y
3、解压到指定位置
tar xf mysql-boost-5.7.37.tar.gz -C /usr/local/src/
4、创建组和用户
[root@host1 mysql-5.7.37]# pwd
/usr/local/src/mysql-5.7.37
[root@host1 mysql-5.7.37]# groupadd -r -g 306 mysql
[root@host1 mysql-5.7.37]# useradd -r -g mysql -u 306 -s /bin/false mysql
5、cmake编译mysql
cmake -DWITH_BOOST=/usr/local/src/mysql-5.7.37/boost \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data
#出现如下问题需要下载openssl-devel包
[root@host1 mysql-5.7.37]# yum install openssl-devel -y
注意:如果解决问题之后,再进行cmake之前必须 make clean;rm CMakeCache.txt
这个时候可以再cmake查看是否还需要进行下包
6、接着etc/my.cnf
7、拷服务脚本并修改权限
cp /usr/local/src/mysql-5.7.37/support-files/mysql.server /etc/init.d/mysqld
查看/etc/init.d/mysqld是否有执行权限如果没有需要添加权限
[root@host1 init.d]# chmod +x mysqld
8、配置mysql的环境变量
[root@host1 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
加载配置
[root@host1 ~]# source /etc/profile.d/mysql.sh
9、做初始化处理(这里有初始密码)
[root@host1 init.d]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
10、启动数据库并登录
[root@host1 init.d]# systemctl start mysqld
[root@host1 init.d]# mysql -uroot -p'rgN_hrpA6.+t'
修改密码
mysql> alter user root@localhost identified by 'MySQL@123';
Query OK, 0 rows affected (0.01 sec)
11、可以自行选择是否开机自启
systemctl enable mysqld
二、多实例安装mysql
方法一:
1、创建组和用户
[root@host2 ~]# groupadd -r -g 306 mysql
[root@host2 ~]# useradd -r -g mysql -u 306 -s /bin/false mysql
2、下载二进制包
[root@host2 ~]# wget -c https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
3、解压到指定位置
[root@host2 ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
4、创建软连接
[root@host2 local]# ln -sv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/ /usr/local/mysql
‘/usr/local/mysql’ -> ‘/usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/’
5、准备数据目录
[root@host2 ~]# mkdir /data/330{6..8}/data -p
6、创建MySQL多实例的配置文件
[root@host2 ~]# vim /data/3306/my.cnf
[client]
port = 3306
socket = /data/3306/mysql.sock
[mysqld]
user = mysql
port = 3306
socket = /data/3306/mysql.sock
basedir = /usr/local/mysql
datadir = /data/3306/data
server-id = 3306
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
log-error=/data/3306/mysql_3306.err
pid-file=/data/3306/mysqld.pid
[root@host2 ~]# cp /data/3306/my.cnf /data/3307/
[root@host2 ~]# cp /data/3306/my.cnf /data/3308/
将文件中的全部的3306分别修改为3307和3308
[root@host2 3307]# sed -i 's/3306/3307/g' /data/3307/my.cnf
[root@host2 3307]# sed -i 's/3306/3308/g' /data/3308/my.cnf
7、修改/data/330{6..8}文件所属组和所属用户
[root@host2 3307]# chown -R mysql.mysql /data/330{6..8}
8、配置mysql的环境变量
[root@host2 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
加载配置
[root@host2 ~]# source /etc/profile.d/mysql.sh
9、初始化实例
3306(YU.EtTmey9t,)、3307(E67xa)X,Kr1-)、3308(e=Idd3qQxu_5)都做如下操作会生成各自的密码
mysqld --initialize --datadir=/data/3306/data --basedir=/usr/local/mysql --user=mysql
mysqld --initialize --datadir=/data/3307/data --basedir=/usr/local/mysql --user=mysql
mysqld --initialize --datadir=/data/3308/data --basedir=/usr/local/mysql --user=mysql
10、创建文件并设置所属用户和所属组
[root@host2 data]# touch /data/3306/mysql_3306.err /data/3307/mysql_3307.err /data/3308/mysql_3308.err
[root@host2 data]# chown mysql.mysql /data/3306/mysql_3306.err /data/3307/mysql_3307.err /data/3308/mysql_3308.err
11、启动多实例
mysqld_safe --defaults-file=/data/3306/my.cnf &
mysqld_safe --defaults-file=/data/3307/my.cnf &
mysqld_safe --defaults-file=/data/3308/my.cnf &
这时候都已经处于监听状态
[root@host2 data]# netstat -lnpt | grep :330
tcp6 0 0 :::3306 :::* LISTEN 15127/mysqld
tcp6 0 0 :::3307 :::* LISTEN 15129/mysqld
tcp6 0 0 :::3308 :::* LISTEN 15680/mysqld
12、登录MySQL
①修改密码
mysqladmin -uroot -p'YU.EtTmey9t,' password 'MySQL@123' -S /data/3306/mysql.sock
mysqladmin -uroot -p'E67xa)X,Kr1-' password 'MySQL@123' -S /data/3307/mysql.sock
mysqladmin -uroot -p'e=Idd3qQxu_5' password 'MySQL@123' -S /data/3308/mysql.sock
②登录MySQL(例举一个)
mysql -uroot -p'MySQL@123' -S /data/3306/mysql.sock
③关闭(例举一个)
mysqladmin -uroot -p'MySQL@123' -S /data/3306/mysql.sock shutdown
方法二:
1、创建多实例配置文件
vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = multi_admin
pass = MySQL@123
[mysqld3306]
socket = /data/3306/mysql.sock
port = 3306
pid-file = /data/3306/mysqld.pid
datadir = /data/3306/data
log-error = /data/3306/mysql_3306.err
[mysqld3307]
socket = /data/3307/mysql.sock
port = 3307
pid-file = /data/3307/mysqld.pid
datadir = /data/3307/data
log-error = /data/3307/mysql_3307.err
[mysqld3308]
socket = /data/3308/mysql.sock
port = 3308
pid-file = /data/3308/mysqld.pid
datadir = /data/3308/data
log-error = /data/3308/mysql_3308.err
!includedir /etc/my.cnf.d
2、修改/data/330{6..8}文件所属组和所属用户
[root@host2 3307]# chown -R mysql.mysql /data/330{6..8}
3、配置mysql的环境变量
[root@host2 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
加载配置
[root@host2 ~]# source /etc/profile.d/mysql.sh
4、初始化实例
同方法一的第9步
5、启动多实例
[root@host2 etc]# mysqld_multi start 3306-3308
初始化密码(3Bz*=c*jXu/t)
[root@host2 etc]# mysqld_multi report
6、授权用户
[root@host2 ~]# mysql -uroot -p'MySQL@123' -S /data/3306/mysql.sock -e "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'MySQL@123'"
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@host2 ~]# mysql -uroot -p'MySQL@123' -S /data/3307/mysql.sock -e "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'MySQL@123'"
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@host2 ~]# mysql -uroot -p'MySQL@123' -S /data/3308/mysql.sock -e "GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'MySQL@123'"
mysql: [Warning] Using a password on the command line interface can be insecure.
7、登录多实例
[root@host2 ~]# mysql -uroot -p'MySQL@123' -S /data/3306/mysql.sock
8、停止多实例
[root@host2 ~]# mysqld_multi stop 3306,3308 [root@host2 ~]# netstat -lnupt | grep :330 tcp6 0 0 :::3307 :::* LISTEN 16739/mysqld
更多推荐
已为社区贡献6条内容
所有评论(0)