Linux安装MySQL 多实例

Linux安装MySQL 多实例

  1. 解压文件
    cd /usr/local 【进入到MySQL安装包位置】
    tar -zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz【解压】
  2. 将解压后文件重命名
    mv 原名 新名↓【mv既可以重命名,又可以移动文件或文件夹】
    mv mysql-5.6.41-linux-glibc2.12-x86_64 mysql3308
  3. 修改当前目录拥有者为mysql用户
    cd /usr/local/mysql3308【进入到MySQL安装位置】
    chown -R mysql:mysql ./【授权命令】
  4. 修改my.cnf 【一般在/etc文件夹里】【注意:!原来的[mysqld]要改名!】
[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqld3307]
port=3307
log-error=/var/log/mysqld3307.log
pid-file=/usr/local/mysql/data/mysqld.pid
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld3308]
port=3308
log-error=/var/log/mysqld3308.log
pid-file=/usr/local/mysql3308/data/mysqld.pid
datadir=/usr/local/mysql3308/data
socket=/usr/local/mysql3308/data/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
  1. 安装数据库及修改权限
    cd /usr/local/mysql3308【进入到MySQL安装位置】
    ./scripts/mysql_install_db --defaults-file=/etc/my.cnf 【安装】
    chown -R root:root ./【修改当前目录拥有者为root用户】
    chown -R mysql:mysql data【修改当前data目录拥有者为mysql用户】
  2. mysqld_multi进行多实例管理

启动全部实例:/usr/local/mysql/bin/mysqld_multi start
查看全部实例状态:/usr/local/mysql/bin/mysqld_multi report
启动单个实例:/usr/local/mysql/bin/mysqld_multi start 3308
停止单个实例:/usr/local/mysql/bin/mysqld_multi stop 3308
查看单个实例状态:/usr/local/mysql/bin/mysqld_multi report 3308

【如果关不掉数据库的话,使用如下语句】
mysqladmin -h127.0.0.1 -P7001 -uroot -p shutdown
报错的话

WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
ABORT: Can't find command 'my_print_defaults'.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.
【解决办法】
export PATH=/usr/local/mysql/bin:$PATH
  1. 进入MySQL
    mysql -h 127.0.0.1 -P 3308 -uroot
    【注意输入分号↓】
    use mysql;【使用mysql库】
    select user,host from user;【查询账号】
    delete from user where user=’’;【删除用户为空的角色】
    update user set password=password(“123456”) where user=‘root’;【更改root密码】
    update user set host=’%’ where host=‘localhost’ and user=‘root’;【%远程链接】
    flush privileges;【刷新MySQL的系统权限相关表】
    exit; 【退出mysql】
  2. Linux开放端口
    开放端口 配置生效 查看

开放端口:firewall-cmd --zone=public --add-port=3308/tcp --permanent
配置生效:firewall-cmd --reload
查看:firewall-cmd --zone=public --list-ports

你可能感兴趣的:(mysql,数据库,Linux)