标签:path maria 技术分享 print tin 初始 配置文件 vim adb
在生产中有时候会遇到一台主机要运行多个MySQL服务器----叫做多实例
下面演示多实例的安装
首先我们规划下
1、创建mysql用户
useradd -r -s /sbin/nologin -d /app/mysql -m mysql # #
2、解压下载的二进制mariadb包
tar xvf mariadb-10.2.16-linux-x86_64.tar.gz -C /usr/local/ # #
3、创建软连接
cd /usr/local/ # ln -s mariadb-10.2.16-linux-x86_64/ mysql #
4、修改权限
chown -R root.mysql /usr/local/mysql/ # #
5、环境变量(少了这步也可)
vim /etc/profile.d/mysql.sh # . /etc/profile.d/mysql.sh #
如果你已经二进制安装了mariadb包,可以从以下开始
1、创建规划图上的目录
mkdir /mysqldb/{3306,3307,3308}/{etc,bin,data,pid,socket,log} -pv # #
2、更改主目录mysqldb的属性
chown -R mysql.mysql /mysqldb/ #
3、3306端口
cd /usr/local/mysql/ # scripts/mysql_install_db --datadir=/mysqldb/3306/data --user=mysql #
4、3307端口
scripts/mysql_install_db --datadir=/mysqldb/3307/data --user=mysql #
5、3308端口
scripts/mysql_install_db --datadir=/mysqldb/3308/data --user=mysql #
1、复制配置文件
cp /etc/my.cnf /mysqldb/3306/etc/ #
2、编辑配置文件
vim /mysqldb/3306/etc/my.cnf #
3、把上面的配置文件当模板传送给3307、3308
cp /mysqldb/3306/etc/my.cnf /mysqldb/3307/etc/ cp /mysqldb/3306/etc/my.cnf /mysqldb/3308/etc/ #
4、更改07、08配置文件的端口
sed -i ‘s/3306/3307/g‘ /mysqldb/3307/etc/my.cnf sed -i ‘s/3306/3308/g‘ /mysqldb/3308/etc/my.cnf #
1、把事先编写的启动脚本复制到06、07、08的bin目录下
cp /root/mysqld /mysqldb/3306/bin/ cp /root/mysqld /mysqldb/3307/bin/ cp /root/mysqld /mysqldb/3308/bin/ #
2、更改7、8的启动脚本进程号为自己的
vim /mysqldb/3307/bin/mysqld #07的改为3307 vim /mysqldb/3308/bin/mysqld #08的改为3308
3、给启动脚本加执行权限
chown +x /mysqldb/3306/bin/mysqld chmod +x /mysqldb/3306/bin/mysqld chmod +x /mysqldb/3307/bin/mysqld chmod +x /mysqldb/3308/bin/mysqld #
4、启动服务脚本
/mysqldb/3306/bin/mysqld start # /mysqldb/3307/bin/mysqld start # /mysqldb/3308/bin/mysqld start
5、ss -ntl查看
1、给数据库root用户加密码
mysqladmin -S /mysqldb/3306/socket/mysql.sock password ‘centos‘ mysqladmin -S /mysqldb/3307/socket/mysql.sock password ‘centos‘ mysqladmin -S /mysqldb/3308/socket/mysql.sock password ‘centos‘
2、进入数据库删除匿名登陆
mysql -S /mysqldb/3306/socket/mysql.sock -uroot -p #
select user,host from mysql.user; #查看有哪些用户 delete from mysql.user where user=‘‘; #删除匿名用户
OK
exit 重新进入 ,如果不行,就重启下服务
#!/bin/bash port=3306 mysql_user="root" mysql_pwd="" cmd_path="/usr/local/bin" mysql_basedir="/mysqldb" mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock" function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MySQL...\n" ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null & else printf "MySQL is running...\n" exit fi } function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MySQL is stopped...\n" exit else printf "Stoping MySQL...\n" ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown fi } function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n" esac
标签:path maria 技术分享 print tin 初始 配置文件 vim adb
原文地址:https://www.cnblogs.com/xsuid/p/9378946.html