tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/ local /mysql57 mv mysql-5.7.19-linux-glibc2.12-x86_64 mysql5719 -- tar -Jxf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz -- mv mysql-8.0.16-linux-glibc2.12-x86_64 /usr/local/mysql80/mysql8016 groupadd mysql ## 添加一个mysql组 useradd -r -g mysql mysql ## 添加一个用户 useradd -r -s /sbin/nologin -g mysql mysql -d /usr/ local /mysql #新建msyql用户禁止登录shell chown -R mysql.mysql /usr/ local /mysql57 --- 5.5、5.6 --MySQL 5.5、5.6的二进制安装默认密码为空 ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql55/mysql5557 --datadir=/usr/local/mysql55/mysql5557/data --defaults-file=/usr/local/mysql55/mysql5557/mysql55573310.cnf ./bin/mysqld_safe --defaults-file=/usr/local/mysql55/mysql5557/mysql55573310.cnf & --MySQL 5.7.6之后的版本初始化数据库不再使用mysql_install_db ./bin/mysqld --defaults-file=/usr/local/mysql57/mysql5719/mysql57193308.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql57/mysql5719 --datadir=/usr/local/mysql57/mysql5719/data ./bin/mysqld_safe --defaults-file=/usr/local/mysql57/mysql5719/mysql57193308.cnf & --同一个版本新建多个实例,和普通安装一样,重新设置配置文件和data文件、端口号 --- mysql -uroot -p -S/usr/local/mysql55/mysql5557/data/mysql55573310.sock cp mysql57193308.cnf mysql57193309.cnf ./bin/mysqld --defaults-file=/usr/local/mysql57/mysql5719/mysql57193308.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql57/mysql5719 --datadir=/usr/local/mysql57/mysql5719/data57193309 ./bin/mysqld_safe --defaults-file=/usr/local/mysql57/mysql5719/mysql57193309.cnf & ---5.5、5.6、5.7修改密码和允许远程登陆 set password = password ( "lhr" ); grant all privileges on *.* to root@ '%' identified by 'lhr' ; flush privileges ; --8.0修改密码和允许远程登陆 update mysql. user set Host= "%" where Host= "localhost" ; update mysql. user set authentication_string= '' where user = 'root' ; ALTER USER 'root' @ '%' IDENTIFIED WITH mysql_native_password BY 'lhr' ; -- 多执行几次 ALTER USER 'root' @ '%' IDENTIFIED WITH mysql_native_password BY 'lhr' ; flush privileges ; select user ,host from mysql. user ; --mysql 8.0远程连接,在参数文件的[mysqld]下添加: default_authentication_plugin=mysql_native_password ----------------mysql57193308.cnf参数文件内容 [mysqld] port=3308 basedir=/usr/ local /mysql57/mysql5719 datadir=/usr/ local /mysql57/mysql5719/data socket=/usr/ local /mysql57/mysql5719/data/mysql57193308.sock server_id=57193308 log-bin --配置开机启动,不适合多实例情况 cp ./support-files/mysql.server /etc/init.d/mysql57193308 chmod 755 /etc/init.d/mysql57193308 chkconfig --add mysql57193308 chkconfig mysql57193308 on chkconfig --level 345 mysql57193308 on service mysql57193308 start ---Linux启动MySQL /usr/ local /mysql55/mysql5557/bin/mysqld_safe --defaults-file=/usr/local/mysql55/mysql5557/mysql55573310.cnf & /usr/ local /mysql55/mysql5557/bin/mysqld_safe --defaults-file=/usr/local/mysql55/mysql5557/mysql55573311.cnf & /usr/ local /mysql56/mysql5637/bin/mysqld_safe --defaults-file=/usr/local/mysql56/mysql5637/mysql56373312.cnf & /usr/ local /mysql56/mysql5637/bin/mysqld_safe --defaults-file=/usr/local/mysql56/mysql5637/mysql56373313.cnf & /usr/ local /mysql57/mysql5719/bin/mysqld_safe --defaults-file=/usr/local/mysql57/mysql5719/mysql57193308.cnf & /usr/ local /mysql57/mysql5719/bin/mysqld_safe --defaults-file=/usr/local/mysql57/mysql5719/mysql57193309.cnf & /usr/ local /mysql80/mysql8016/bin/mysqld_safe --defaults-file=/usr/local/mysql80/mysql8016/mysql80163314.cnf & /usr/ local /mysql80/mysql8016/bin/mysqld_safe --defaults-file=/usr/local/mysql80/mysql8016/mysql80163315.cnf & ---Linux关闭MySQL /usr/ local /mysql55/mysql5557/bin/mysqladmin -u root -plhr -S/usr/ local /mysql55/mysql5557/data/mysql55573310.sock shutdown /usr/ local /mysql55/mysql5557/bin/mysqladmin -u root -plhr -S/usr/ local /mysql55/mysql5557/data55573311/mysql55573311.sock shutdown /usr/ local /mysql56/mysql5637/bin/mysqladmin -u root -plhr -S/usr/ local /mysql56/mysql5637/data/mysql56373312.sock shutdown /usr/ local /mysql56/mysql5637/bin/mysqladmin -u root -plhr -S/usr/ local /mysql56/mysql5637/data56373313/mysql56373313.sock shutdown /usr/ local /mysql57/mysql5719/bin/mysqladmin -u root -plhr -S/usr/ local /mysql57/mysql5719/data/mysql57193308.sock shutdown /usr/ local /mysql57/mysql5719/bin/mysqladmin -u root -plhr -S/usr/ local /mysql57/mysql5719/data57193309/mysql57193309.sock shutdown /usr/ local /mysql80/mysql8016/bin/mysqladmin -u root -plhr -S/usr/ local /mysql80/mysql8016/data/mysql80163314.sock shutdown /usr/ local /mysql80/mysql8016/bin/mysqladmin -u root -plhr -S/usr/ local /mysql80/mysql8016/data80163315/mysql80163315.sock shutdown 启动全部实例:mysqld_multi start 查看全部实例状态:mysqld_multi report 启动单个实例:mysqld_multi start 3306 停止单个实例:mysqld_multi stop 3306 查看单个实例状态:mysqld_multi report 3306 ---------------------- /etc/my.cnf 管理多实例 [mysqld_multi] mysqld=/usr/ local /mysql80/mysql8016/bin/mysqld_safe mysqladmin=/usr/ local /mysql80/mysql8016/bin/mysqladmin log=/usr/ local /mysql80/log/mysqld_multi.log user =root password =lhr [client] port=3308 socket=/usr/ local /mysql57/mysql5719/data/mysql57193308.sock user =root host=localhost password =lhr [mysql] default - character - set =utf8 [mysqld56213306] mysqld=/usr/ local /mysql55/mysql5557/bin/mysqld_safe mysqladmin=/usr/ local /mysql55/mysql5557/bin/mysqladmin log-bin basedir=/usr datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user =mysql slow_query_log=1 slow_query_log_file=/var/lib/mysql/rhel6lhr-slow.log [mysqld55573310] mysqld=/usr/ local /mysql55/mysql5557/bin/mysqld_safe mysqladmin=/usr/ local /mysql55/mysql5557/bin/mysqladmin port=3310 basedir=/usr/ local /mysql55/mysql5557 datadir=/usr/ local /mysql55/mysql5557/data socket=/usr/ local /mysql55/mysql5557/data/mysql55573310.sock server_id=55573310 log-bin [mysqld55573311] mysqld=/usr/ local /mysql55/mysql5557/bin/mysqld_safe mysqladmin=/usr/ local /mysql55/mysql5557/bin/mysqladmin port=3311 basedir=/usr/ local /mysql55/mysql5557 datadir=/usr/ local /mysql55/mysql5557/data55573311 socket=/usr/ local /mysql55/mysql5557/data55573311/mysql55573311.sock server_id=55573311 log-bin [mysqld56373312] mysqld=/usr/ local /mysql56/mysql5637/bin/mysqld_safe mysqladmin=/usr/ local /mysql56/mysql5637/bin/mysqladmin port=3312 basedir=/usr/ local /mysql56/mysql5637 datadir=/usr/ local /mysql56/mysql5637/data socket=/usr/ local /mysql56/mysql5637/data/mysql56373312.sock server_id=56373312 log-bin [mysqld56373313] mysqld=/usr/ local /mysql56/mysql5637/bin/mysqld_safe mysqladmin=/usr/ local /mysql56/mysql5637/bin/mysqladmin port=3313 basedir=/usr/ local /mysql56/mysql5637 datadir=/usr/ local /mysql56/mysql5637/data56373313 socket=/usr/ local /mysql56/mysql5637/data56373313/mysql56373313.sock server_id=56373313 log-bin [mysqld57193308] mysqld=/usr/ local /mysql57/mysql5719/bin/mysqld_safe mysqladmin=/usr/ local /mysql57/mysql5719/bin/mysqladmin port=3308 basedir=/usr/ local /mysql57/mysql5719 datadir=/usr/ local /mysql57/mysql5719/data socket=/usr/ local /mysql57/mysql5719/data/mysql57193308.sock server_id=57193308 log-bin [mysqld57193309] mysqld=/usr/ local /mysql57/mysql5719/bin/mysqld_safe mysqladmin=/usr/ local /mysql57/mysql5719/bin/mysqladmin port=3309 basedir=/usr/ local /mysql57/mysql5719 datadir=/usr/ local /mysql57/mysql5719/data57193309 socket=/usr/ local /mysql57/mysql5719/data57193309/mysql57193309.sock server_id=57193309 log-bin [mysqld80163314] mysqld=/usr/ local /mysql80/mysql8016/bin/mysqld_safe mysqladmin=/usr/ local /mysql80/mysql8016/bin/mysqladmin port=3314 basedir=/usr/ local /mysql80/mysql8016 datadir=/usr/ local /mysql80/mysql8016/data socket=/usr/ local /mysql80/mysql8016/data/mysql80163314.sock default_authentication_plugin=mysql_native_password server_id=80163314 log-bin [mysqld80163315] mysqld=/usr/ local /mysql80/mysql8016/bin/mysqld_safe mysqladmin=/usr/ local /mysql80/mysql8016/bin/mysqladmin port=3315 basedir=/usr/ local /mysql80/mysql8016 datadir=/usr/ local /mysql80/mysql8016/data80163315 socket=/usr/ local /mysql80/mysql8016/data80163315/mysql80163315.sock default_authentication_plugin=mysql_native_password server_id=80163315 log-bin |