加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例

发布时间:2020-12-12 02:28:29 所属栏目:MySql教程 来源:网络整理
导读:《Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例》要点: 本文介绍了Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例,希望对您有用。如果有疑问,可以联系我们。 本文讲应用MySQL源码安装MySQL并用mysqld_multi配置多实例.

《Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例》要点:
本文介绍了Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例,希望对您有用。如果有疑问,可以联系我们。

本文讲应用MySQL源码安装MySQL并用mysqld_multi配置多实例.MYSQL学习

1、下载MySQL源码安装版本MYSQL学习

到MySQL官网查找到相应版本下载,本文下载的是5.1版本MYSQL学习

代码如下:
wget -c ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.1/mysql-5.1.60.tar.gz?

2、解压安装MYSQL学习

代码如下:
tar -zxv -f mysql-5.1.60.tar.gz?
?
./configure --prefix=/usr/local/mysql --with-charset=utf8??
--with-extra-charset=all --enable-thread-safe-client --enable-assembler??
--with-readline --with-big-tables??
--with-named-curses-libs=/usr/lib/libncursesw.so.5?
?
make && make install?

3、添加用户和用户组MYSQL学习

代码如下:
groupadd mysql #添加mysql用户组?
useradd -g mysql mysql #创立mysql用户并把它放到mysql组下?
chown -R root:mysql /usr/local/mysql #修改mysql文件属性?

4、初始化数据目录MYSQL学习

代码如下:
#把用到的工具添加到/usr/bin目录?
ln -s /usr/local/mysql/bin/mysqld_multi /usr/bin/mysqld_multi?
ln -s /usr/local/mysql/bin/mysql_install_db /usr/bin/mysql_install_db?
?
#初始化四个数据目录?
mysql_install_db --datadir=/usr/local/var/mysql1 --user=mysql?
mysql_install_db --datadir=/usr/local/var/mysql2 --user=mysql?
mysql_install_db --datadir=/usr/local/var/mysql3 --user=mysql?
mysql_install_db --datadir=/usr/local/var/mysql4 --user=mysql?
?
#改动属性?
chown -R mysql /usr/local/var/mysql1??
chown -R mysql /usr/local/var/mysql2?
chown -R mysql /usr/local/var/mysql3??
chown -R mysql /usr/local/var/mysql4??

5、配置多实例启动脚本MYSQL学习

??? 从MySQL的源码中把复制到/etc/init.d/目次下MYSQL学习

代码如下:
cp /usr/local/src/mysql-5.1.60/support-files/mysqld_multi.server /etc/init.d/mysqld_multi.server?
?
#改动basedir和bindir为安装路径?
basedir=/usr/local/mysql?
bindir=/usr/local/mysql/bin?

6、配置多实例数据库配置文件MYSQL学习

用mysqld_multi工具查看该配置文件的模板办法,命令为:mysqld_multi --example
在/etc/目录下创建创建文件/etc/mysqld_multi.cnf,把mysqld_multi --example产生的文件粘进去,修改相应属性,如:mysqld,mysqladmin,socket,port,pid-file,datadir,user等.
MYSQL学习

代码如下:
[mysqld_multi]?
mysqld???? = /usr/local/mysql/bin/mysqld_safe?
mysqladmin = /usr/local/mysql/bin/mysqladmin?
#user?????? = mysql?
#password?? = my_password?
?
[mysqld1]?
socket???? = /usr/local/var/mysql1/mysql1.sock?
port?????? = 3306?
pid-file?? = /usr/local/var/mysql1/mysql1.pid?
datadir??? = /usr/local/var/mysql1?
#language?? = /usr/local/mysql/share/mysql/english?
user?????? = mysql?
?
[mysqld2]?
socket???? = /usr/local/var/mysql2/mysql2.sock?
port?????? = 3307?
pid-file?? = /usr/local/var/mysql2/mysql2.pid?
datadir??? = /usr/local/var/mysql2?
#language?? = /usr/local/mysql/share/mysql/english?
user?????? = mysql?
?
[mysqld3]?
socket???? = /usr/local/var/mysql3/mysql3.sock?
port?????? = 3308?
pid-file?? = /usr/local/var/mysql3/mysql3.pid?
datadir??? = /usr/local/var/mysql3?
#language?? = /usr/local/mysql/share/mysql/english?
user?????? = mysql?
?
[mysqld4]?
socket???? = /usr/local/var/mysql4/mysql4.sock?
port?????? = 3309?
pid-file?? = /usr/local/var/mysql4/mysql4.pid?
datadir??? = /usr/local/var/mysql4?
#language?? = /usr/local/mysql/share/mysql/english?
user?????? = mysql?

7、启动多实例数据库
MYSQL学习

代码如下:
将/usr/local/mysql/bin加到$PATH环境变量里?
export PATH=/usr/local/mysql/bin:$PATH?
?
#查看数据库状态?
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report?
#成果都为没有运行?
Reporting MySQL servers?
MySQL server from group: mysqld1 is not running?
MySQL server from group: mysqld2 is not running?
MySQL server from group: mysqld3 is not running?
MySQL server from group: mysqld4 is not running?
?
#启动?
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf start?
#成果为?
Reporting MySQL servers?
MySQL server from group: mysqld1 is not running?
MySQL server from group: mysqld2 is not running?
MySQL server from group: mysqld3 is not running?
MySQL server from group: mysqld4 is not running?
?
#启动具体某一个实例可在start、stop后面加上具体数据1,2,3等?

8、查看运行成果MYSQL学习

代码如下:
#查看相应端口是否已经被监听?
netstat -tunlp?
?
#查看是否有活动过程?
ps -aux|grep mysql?

9、登录相应数据库MYSQL学习

代码如下:
#进入端口为3306的数据库?
mysql -uroot -p -h127.0.0.1 -P3306?
?
#经由过程sock文件登录?
mysql -uroot -p -S /usr/local/var/mysql1/mysql1.sock?
?
?#查看socket文件?
mysql> SHOW VARIABLES LIKE 'socket';?
?
#查看pid文件?
mysql> SHOW VARIABLES LIKE '%pid%';?

《Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例》是否对您有启发,欢迎查看更多与《Mysql入门使用mysqld_multi实现单系统中配置多个MySQL服务器实例》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读