centos 7 安装 mysql5.7,自定义目录
平台: centos 7
shell命令:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
shell> yum search libaio shell> yum install libaio shell> mkdir /home/admin/temp shell> mkdir /prod/db shell> cd /home/admin/temp shell> wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz shell> tar -axvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /prod/db shell> mv /prod/db/mysql-5.7.27-linux-glibc2.12-x86_64 mysql shell> cd /prod/db/mysql shell> ls shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> ln -s /prod/db/mysql mysql shell> mysql/bin/mysqld --user=mysql --basedir=/prod/db/mysql --datadir=/prod/db/mysql/data/ --initialize
mysql命令
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; FLUSH PRIVILEGES; exit
my.cnf配置文件:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[client] port = 3306 socket = /prod/db/mysql/mysql.sock [mysqld] port = 3306 basedir=/prod/db/mysql datadir=/prod/db/mysql/data socket=/prod/db/mysql/mysql.sock pid-file=/prod/db/mysql/mysql.pid explicit_defaults_for_timestamp log_error=/prod/db/mysql/log/mysql-error.log slow_query_log_file =/prod/db/mysql/log/mysql-slow.log
mysql5.7x安装路径:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
本次使用的安装包url: https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
mysql5.7x依赖库: libaio
查询是否已安装依赖库: yum search libaio
安装依赖库: yum install libaio
创建临时目录: mkdir /home/admin/temp
新建软件安装目录: mkdir /prod/db
进入templ目录: cd /home/admin/temp
下载安装包: wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
解压安装包,到软件安装目录(-C 是指定解压的目标目录): tar -axvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz -C /prod/db
重命名mysql: mv /prod/db/mysql-5.7.27-linux-glibc2.12-x86_64 mysql
进入mysql目录: cd /prod/db/mysql
查询mysql目录文件: ls
创建mysql用户组:groupadd mysql
创建mysql用户(-s /bin/false 是禁止用户登录centos系统):useradd -r -g mysql -s /bin/false mysql
创建软连接: ln -s /prod/db/mysql mysql
初始化mysql环境:mysql/bin/mysqld --user=mysql --basedir=/prod/db/mysql --datadir=/prod/db/mysql/data/ --initialize
得到mysql的临时登录密码:
使用临时密码登录:mysql -u root -p"刚刚得到临时的密码"
修改密码(password() 里面填写你要设定的密码):set password=password('yourpassword');
设置远程登录:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
重载授权表:FLUSH PRIVILEGES;
退出mysql数据库:exit
官网安装文档(参考):https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html