mysql单机多实例:
vim /etc/my3307.cnf
cat /etc/my3307.cnf
[mysqld]
datadir=/data/3307/
socket=/data/3307/mysql.sock
port=3307
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/data/3307/mysqld.log
pid-file=/data/3307/mysqld.pid
cp /etc/my3307.cnf /etc/my3308.cnf
sed -i 's#3307#3308#g' /etc/my3308.cnf
mkdir /data/{3307,3308}
chown -R mysql:mysql /data/330*
报错内容如下1:
[root@localhost ~]# mysql_install_db --user=mysql --defaults-file=/etc/my3308.cnf –-datadir=/data/3308/
Neither host 'web01.test.com' nor 'localhost' could be looked up with
'/usr/libexec/resolveip'
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
The latest information about mysql_install_db is available at
https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
解决:
方法一:
按照网上的解决办法是:更改/etc/hosts;
1、首先用cat查看/etc/hosts文件,会显示以下内容:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
可见/etc/hosts中无相应的机器名
需添加本机的ip到/etc/hosts中:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 DB01
2、使用resolveip确认是否ok
#/usr/local/mysql/bin/resolveip DB01
IP address of DB01 is 127.0.0.1
说明已经OK了,再次运行mysql安装程序即可。
测试结果:
[root@localhost ~]# resolveip web01
IP address of web01 is 127.0.0.1
经测试发现无法实现初始化,原因可能是出现在它是二进制源码包安装,我这采用的是rpm安装,在"resolveip"的路径上面会有很大的出入,所以我通过"which resolveip" 查看路径,将resolveip这个文件复制到/usr/libexec/下:
方法二:
resolveip -I #查看当前resolveip的版本是否为64为
rpm -qa mariadb-server #mariadb-server-5.5.64-1.el7.x86_64
cp /usr/bin/resolveip /usr/libexec/
mysql_install_db --user=mysql --defaults-file=/etc/my3307.cnf #这里将不指定--datadir参数,原因是,在指定这个参数之后,在下一步启动时报错。参考"报错内容如下2";
mysqld_safe --defaults-file=/etc/my3307.cnf & #启动多实例
测试结果:初始化并启动成功
报错内容如下2:
200330 10:37:38 InnoDB: Waiting for the background threads to start
200330 10:37:39 Percona XtraDB (http://www.percona.com) 5.5.61-MariaDB-38.13 started; log sequence number 0
200330 10:37:39 [Note] Plugin 'FEEDBACK' is disabled.
200330 10:37:39 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
200330 10:37:39 [Note] Server socket created on IP: '0.0.0.0'.
200330 10:37:39 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
200330 10:37:39 mysqld_safe mysqld from pid file /data/3307/mysqld.pid ended
200330 10:51:48 mysqld_safe Starting mysqld daemon with databases from /data/3307/
200330 10:51:48 [Note] /usr/libexec/mysqld (mysqld 5.5.64-MariaDB) starting as process 996 ...
200330 10:51:48 InnoDB: The InnoDB memory heap is disabled
200330 10:51:48 InnoDB: Mutexes and rw_locks use GCC atomic builtins
200330 10:51:48 InnoDB: Compressed tables use zlib 1.2.7
200330 10:51:48 InnoDB: Using Linux native AIO
200330 10:51:48 InnoDB: Initializing buffer pool, size = 128.0M
200330 10:51:48 InnoDB: Completed initialization of buffer pool