-
- 单实例安装
cp /soft/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
具体安装
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 770 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
记住初始化产生的密码
password a generated for root@localhost:MYy.)hutk1_c
shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server //复制配置到指定地方 用于配置开机启动
设置开机启动
Chkconfig --list 查看开机启动项目
Chkconfig mysql.server on 配置mysql开机启动
配置环境变量:/etc/profile 里面 最后export PATH=/usr/local/mysql/bin:$PATH
然后重新加载该文件 source /etc/profile
登陆,修改密码
set password = 'root1234%';
允许远程登陆
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234%'
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234%' WITH GRANT OPTION;
flush privileges;
这种方法并不适用于Mysql 8.0以后的版本,
- CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';
- GRANT ALL ON *.* TO 'root'@'%';
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
- flush privileges;
启动的时候可能会报错
这是因为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文件