CentOS6.8编译安装MySQL5.5.32(二多实例)
MySQL多实例的配置
瓦房店ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!
通过上文 CentOS 6.8 编译安装MySQL5.5.32 ,我们完成了编译安装,接下配置多实例
本图借鉴徐亮伟"思维简图"
5,添加多实例目录
[root@db01 application]# mkdir -p /data/{3306,3307}/data [root@db01 application]# tree /data/ /data/ ├── 3306 │ └── data └── 3307 └── data,
6,上传多实例配置文件
[root@db01 /]# cd / [root@db01 /]# rz -y data.zip [root@db01 /]# unzip data.zip [root@db01 /]# tree data data ├── 3306 ##3306实例目录 │ ├── data │ ├── my.cnf │ └── mysql └── 3307 ├── data ├── my.cnf └── mysql
##多实例 文件对比 配置文件中 只有字符串 3306与3307,与serverID 的不同
7,给Mysql启动脚本增加执行权限
find /data -type f -name "mysql"|xargs chmod 700 chown -R mysql.mysql /data
8,多实例初始化,作用就是加载mysql自带的库与表##
cd /application/mysql/scripts ./mysql_install_db --defaults-file=/data/3306/my.cnf --basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql ./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql ##提示:--basedir=/application/mysql/为MySQL的安装路径,--datadir为数据文件目录。 另,注意mysql_install_db和MySQL5.1的路径不同,MySQL5.1不在MySQL bin路径下了。
编译过程,注意要有2个OK 才算成功
[root@db02 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql WARNING: The host 'db02' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! Installing MySQL system tables... OK #<==两个OK是初始化成功的标志。 Filling help tables... OK #<==两个OK是初始化成功的标志。 To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /application/mysql/bin/mysqladmin -u root password 'new-password' /application/mysql/bin/mysqladmin -u root -h db02 password 'new-password' Alternatively you can run: /application/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /application/mysql ; /application/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /application/mysql/mysql-test ; perl mysql-test-run.pl Please report any problems with the /application/mysql/scripts/mysqlbug script! ###请注意如下几行英文的说明及报错 New default config file was createdas /application/mysql//my.cnf and will be used by default by theserver when you start it. You may edit this file to changeserver settings #从上文说明中可以指导mysql的默认配置文件已经变到了/application/mysql//my.cnf WARNING: Default config file/etc/my.cnf exists on the system This file will be read by defaultby the MySQL server If you do not want to use this,either remove it, or use the --defaults-file argument tomysqld_safe when starting the server #从上文说明中可以看到数据库启动时会读取/etc/my.cnf,因此有可能会导致无法启动,避免的方法就是使用mysqld_safe启动服务时采用--defaults-file参数指定配置文件,前文已将/etc/my.cnf改名了,所以,就不需要指定参数了,这里是一个坑,读者要注意。 此步骤必须要初始化成功,否则,后面会出现登录不了数据库等各种问题。 [root@oldboy ~]# mysql ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 解决办法:重新初始化数据库即可,此问题一般都是数据库初始化问题,或者数据库文件损坏,以及目录权限问题
9,MySQL 初始化原理
初始化数据库的就是加载MySQL自带的库与表 例如:生成的test及mysql库表等。
初始化数据库后,查看数据目录,生成哪些文件
[root@db02 scripts]# ls -l /data/3306/data/ total 143372 -rw-rw---- 1 mysql mysql 134217728 Apr 29 03:32 ibdata1 -rw-rw---- 1 mysql mysql 4194304 Apr 29 03:32 ib_logfile0 -rw-rw---- 1 mysql mysql 4194304 Apr 29 03:32 ib_logfile1 -rw-rw---- 1 mysql mysql 4194304 Apr 29 03:32 ib_logfile2 drwx------ 2 mysql root 4096 Apr 29 03:31 mysql ##用于存放管理mysql数据 drwx------ 2 mysql mysql 4096 Apr 29 03:31 performance_schema #内部性能库 drwx------ 2 mysql root 4096 Apr 29 03:31 test ##测试库
10,启动MySQL 命令 多实例(3306/3307)
[root@db02 scripts]# /data/3306/mysql start ##启动脚本见百度云连接 Starting MySQL... [root@db02 scripts]# /data/3307/mysql start Starting MySQL... [root@db02 scripts]# ps -ef|grep 330 root 13426 1 0 11:32 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf mysql 14150 13426 0 11:32 pts/1 00:00:05 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/mysql_oldboy3306.err --open-files-limit=1024 --pid-file=/data/3306/mysqld.pid --socket=/data/3306/mysql.sock --port=3306 root 17840 1 0 12:57 pts/1 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf mysql 18540 17840 15 12:57 pts/1 00:00:01 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/mysql_oldboy3307.err --open-files-limit=1024 --pid-file=/data/3307/mysqld.pid --socket=/data/3307/mysql.sock --port=3307 root 18558 1286 0 12:57 pts/1 00:00:00 grep --color=auto 330 ##如果启动失败,请检查日志,路径是在 每个实例下都有个err文件,例如下面的3306 [root@db02 scripts]# vi /data/3306/mysql_oldboy3306.err #MySQL5.6.36版本会出现如下错误: [root@db02 scripts]# /data/3306/mysql start Starting MySQL... 170508 12:56:08 mysqld_safe error: log-error set to '/data/3306/oldboy_3306.err', however file don't exists. Create writable for user 'mysql'. #解决方法: touch /data/3306/oldboy_3306.err chown mysql.mysql /data/3306/oldboy_3306.err /data/3306/mysql start ##3307实例也是如此操作,主要是缺少错误日志文件导致无法启动
11,连接MySQL数据库( 以socket区分,多实例)
[root@db02 scripts]# mysql -uroot -p -S /data/3306/mysql.sock #-S指定要启动实例的socket-bash: mysql: command not found #报错是因为没有设定环境变量 解决方法的两种思路: (建议使用第二种) 1)将mysql 路径添加到环境变量 echo "PATH=$PATH:/application/mysql/bin/">>/etc/profile source /etc/profilep 2)将mysql 需要执行的文件或脚本,拷贝到第一个已经有环境变量权限的目录下,去执行。 cp /application/mysql/bin/* /usr/local/sbin/ 再次连接,登录3306 [root@db02 ~]# mysql -uroot -p -S /data/3306/mysql.sock [root@db02 ~]# mysql -uroot -p -S /data/3307/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.32-log Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
12,添加开机自启动 (多实例 multi instances)
[root@db02 ~]# echo "# mysql multi instances" >>/etc/rc.local #添加注释,及实例启动项 [root@db02 ~]# echo "/data/3306/mysql start " >>/etc/rc.local [root@db02 ~]# echo "/data/3307/mysql start " >>/etc/rc.loca
13,新增一个3308实例
mkdir -p /data/3308/data \cp /data/3306/my.cnf /data/3308/ \cp /data/3306/mysql /data/3308/ sed -i 's/3306/3308/g' /data/3308/my.cnf sed -i 's/server-id = 6/server-id = 8/g' /data/3308/my.cnf sed -i 's/3306/3308/g' /data/3308/mysql chown -R mysql:mysql /data/3308 chmod 700 /data/3308/mysql cd /application/mysql/scripts ./mysql_install_db --defaults-file=/data/3308/my.cnf --datadir=/data/3308/data --basedir=/application/mysql --user=mysql chown -R mysql:mysql /data/3308 egrep "server-id|log-bin" /data/3308/my.cnf touch /data/3308/oldboy_3308.err chown mysql /data/3308/oldboy_3308.err /data/3308/mysql start #mysql启动慢,如果此段命令放到脚本中支持,需要sleep 3-5秒 netstat -lnt|grep 3308
测试3308实例
[root@db02 scripts]# mysqld_safe /data/3308/mysql.sock #目前已启动3个实例 [root@db02 scripts]# netstat -lnt|grep 330 tcp 0 0 :::3306 :::* LISTEN tcp 0 0 :::3307 :::* LISTEN tcp 0 0 :::3308 :::* LISTEN
14,Mysql多实例启动故障排错说明
如果MySQL多实例有服务没有被启动,排除方法如下:
如果发现没有显示MySQL对应的实例端口,请稍微等待几秒在检查,MySQL服务的启动稍慢
如果还是不行,请查看MySQL实例对应的错误日志,路径在my.cnf配置文件中最下面定义:
例如:3306实例的错误日志为:/data/3306/*.err
细看所有执行命令返回的屏幕输出,不要忽略关键的输出内容。
辅助查看系统日志/var/log/messages
如果是MySQL关联了其他服务,同时查看相关服务日志
仔细阅读,重新查看操作的步骤是否正确,书写命令及字符串是否正确。
多看日志,多多总结,终究会称为高手的。
新闻名称:CentOS6.8编译安装MySQL5.5.32(二多实例)
文章路径:http://ybzwz.com/article/jgggsd.html