mysql5.6版本多配置文件安装实例
程序员文章站
2022-07-03 09:50:55
mysql5.6版本多配置文件安装实例
为新实例创建数据目录并赋权
#创建两个目录分别作为两个实例的数据目录
mkdir -p /data/application/mys...
mysql5.6版本多配置文件安装实例
为新实例创建数据目录并赋权
#创建两个目录分别作为两个实例的数据目录 mkdir -p /data/application/mysql-multi-instance/{mysql3307, mysql3308} #为两个实例的数据目录赋权,避免在初始化数据库时出错 chown mysql:mysql -R /data/application/mysql-multi-instance/{mysql3307, mysql3308}
使用mysql的mysql_install_db实例化数据库
./mysql_install_db --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3307 --user=mysql ./mysql_install_db --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3308 --user=mysql
编辑两个实例的配置文件
#这是3307实例的配置文件 [client] port = 3307 socket = /tmp/mysql3307.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3307 socket = /tmp/mysql3307.sock basedir = /data/application/mysql datadir = /data/application/mysql-multi-instance/mysql3307 [mysqldump] quick max_allowed_packet = 2M [mysqld_safe] log-error=/data/application/mysql-multi-instance/mysql3307/mysql_3307.err pid-file=/data/application/mysql-multi-instance/mysql3307/mysqld.pid
#这是3308实例的配置文件 [client] port = 3308 socket = /tmp/mysql3308.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3308 socket = /tmp/mysql3308.sock basedir = /data/application/mysql datadir = /data/application/mysql-multi-instance/mysql3308 [mysqldump] quick max_allowed_packet = 2M [mysqld_safe] log-error=/data/application/mysql-multi-instance/mysql3308/mysql_3308.err pid-file=/data/application/mysql-multi-instance/mysql3308/mysqld.pid
启动实例
mysqld_safe --defaults-file=/data/application/etc/mysql3307.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3307 --user=mysql & mysqld_safe --defaults-file=/data/application/etc/mysql3308.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3308 --user=mysql &
查看启动结果
#这里开启了默认的3306实例,所以有三个实例 root 6794 1 0 Oct26 ? 00:00:00 /bin/sh /data/application/mysql/bin/mysqld_safe --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --user=mysql mysql 6902 6794 0 Oct26 ? 00:00:37 /data/application/mysql/bin/mysqld --defaults-file=/data/application/mysql/my.cnf --basedir=/data/application/mysql --datadir=/data/application/mysqlData --plugin-dir=/data/application/mysql/lib/plugin --user=mysql --log-error=/data/application/mysqlData/iZuf60tfg75y5orqql6pluZ.err --pid-file=/data/application/mysqlData/iZuf60tfg75y5orqql6pluZ.pid root 16375 11905 0 19:31 pts/3 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/application/etc/mysql3307.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3307 --user=mysql mysql 16560 16375 0 19:31 pts/3 00:00:00 /data/application/mysql/bin/mysqld --defaults-file=/data/application/etc/mysql3307.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3307 --plugin-dir=/data/application/mysql/lib/plugin --user=mysql --log-error=/data/application/mysql-multi-instance/mysql3307/mysql_3307.err --pid-file=/data/application/mysql-multi-instance/mysql3307/mysqld.pid --socket=/tmp/mysql3307.sock --port=3307 root 16605 11905 0 19:50 pts/3 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/application/etc/mysql3308.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3308 --user=mysql mysql 16789 16605 0 19:50 pts/3 00:00:00 /data/application/mysql/bin/mysqld --defaults-file=/data/application/etc/mysql3308.cnf --basedir=/data/application/mysql --datadir=/data/application/mysql-multi-instance/mysql3308 --plugin-dir=/data/application/mysql/lib/plugin --user=mysql --log-error=/data/application/mysql-multi-instance/mysql3308/mysql_3308.err --pid-file=/data/application/mysql-multi-instance/mysql3308/mysqld.pid --socket=/tmp/mysql3308.sock --port=3308
修改密码
mysqladmin -u root password -S /tmp/mysql3307.sock mysqladmin -u root password -S /tmp/mysql3308.sock
至此记录完毕