centos 7下mysql安装步骤

    技术2022-07-10  90

    本文以centos7为例,介绍mysql5.7的安装过程,由于系统版本不同,安装过程可能存在稍许差异,但本文介绍的过程还是可以参考的。 1.单实例安装 set global show_compatibility_56=on;

    下载mysql安装文件mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz到/usr/local/

    解压 mysql 到/usr/local 目录 解压: tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

    安装需要的依赖 yum install -y libaio 具体安装如下: [root@localhost local]# groupadd mysql [root@localhost local]# useradd -r -g mysql mysql [root@localhost local]# cd /usr/local [root@localhost local]# mv mysql-5.7.9 mysql [root@localhost local]# cd mysql [root@localhost local]# mkdir mysql-files [root@localhost local]# chmod 770 mysql-files [root@localhost local]# chown -R mysql . [root@localhost local]# chgrp -R mysql . [root@localhost local]# bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up [root@localhost local]# bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up [root@localhost local]# chown -R root . [root@localhost local]# chown -R mysql data mysql-files [root@localhost local]# bin/mysqld_safe --user=mysql &

    ###Next command is optional [root@localhost local]# cp support-files/mysql.server /etc/init.d/mysql.server

    配置环境变量: export PATH=/usr/local/mysql/bin:$PATH 配置开机启动 chkconfig mysql.server on chkconfig --list

    启动mysql service mysql start

    启动的时候有可能会报错 这是因为 mysql 启动的时候需要配置文件,而在安装 centos 的时候,哪怕是 mini 版本都会有个默认的配置在/etc 目录中 /usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 ‘Default options’ Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf Mysql 启动的时候会以上面所述的顺序加载配置文件 配置内容参考如下: 如果报错,先重命名 my.cnf 文件,也可以指定一个带绝对路径的配置文件进行启动

    登陆,修改密码 mysql -uroot -p123456

    mysql> set password = ‘pass1234%’; 允许远程登陆 mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘pass1234%’ mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘pass1234%’ WITH GRANT OPTION; mysql> flush privileges;

    2.多实例安装 以前有一些很 low 的方法是,解压两个 mysql,分别放到不同文件夹,其实 mysql 已经考虑到了多实例安装的情况。也有相应的脚本命令的支持。 现在要求装两个 mysql 一个 3306,3308

    新建 /etc/my.cnf 配置如下 [mysqld] sql_mode = “STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR _FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER” [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin log = /var/log/mysqld_multi.log [mysqld1] server-id = 11 socket = /tmp/mysql.sock1 port = 3306 datadir = /data1 user = mysql performance_schema = off innodb_buffer_pool_size = 32M skip_name_resolve = 1 log_error = error.log pid-file = /data1/mysql.pid1 [mysqld2] server-id = 12 socket = /tmp/mysql.sock2 port = 3308 datadir = /data2 user = mysql performance_schema = off innodb_buffer_pool_size = 32M skip_name_resolve = 1 log_error = error.log pid-file = /data2/mysql.pid2

    创建 2 个数据目录 mkdir /data1 mkdir /data2 chown mysql.mysql /data1 chown mysql.mysql /data2 mysqld --initialize --user=mysql --datadir=/data1 mysqld --initialize --user=mysql --datadir=/data2 cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multid

    配置开机启动 chkconfig mysqld_multid on 查看状态 mysqld_multi report 如果出现这个提示,说明还需要 perl 的环境,安装 yum -y install perl perl-devel 在运行,就发现已经有实例了 mysqld_multi report mysqld_multi start

    启动,登录,分别修改密码,允许远程连接 mysql -u root -S /tmp/mysql.sock1 -p123456 -P3306 mysql -u root -S /tmp/mysql.sock2 -p123456 -P3308

    mysql> set password = ‘pass1234%’; mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘pass1234%’; mysql> flush privileges;

    Processed: 0.027, SQL: 9