将mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 上传到centos服务器
1.解压安装
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz #解压
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql #启动目录、重命名
2.创建mysql用户/组
cd /usr/local/mysql
mkdir data
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin -d /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql #将mysql目录所属用户指定为mysql用户
3.初始化mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
记住上面命令产生的临时密码,后面会用到。如临时密码为 f,u!bniWI8s9
创建RSA private key:
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
4.修改配置文件
cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
cp /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
character_set_server=utf8
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/tmp/mysql.sock
5.启动mysql
service mysql start 开启服务
其他相关命令:
service mysql stop 停止服务
service mysql status 查看状态
service mysql restart 重启服务
6.连接mysql并设置root密码
cd /usr/local/mysql/bin
./mysql -u root -p
[输入临时密码,回车]
#设置root用户密码
set password for 'root'@'localhost' =password('123456');
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges ;
7.设置mysql服务自开机启动
chkconfig mysql on
8.配置mysql环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$JAVA_HOME/bin:$MYSQL_HOME/bin
:x保存退出
source /etc/profile #使之立即生效