二进制安装包安装mysql-5.7.13

时间:2021-11-12 20:06:09
1. 下载并上传 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

tar -zxf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz #解压

2. 建立安装目录,并拷贝文件

mkdir /u01
mv mysql-5.7.13-linux-glibc2.5-x86_64 /u01/mysql-5.7.13
ln -s /u01/mysql-5.7.13 /u01/mysql

3. 建立用户及用户组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
# -s /bin/false 禁止一切服务使用


4.建立数据库文件

cd /u01/mysql
mkdir mysql-files # 建立数据文件目录

5.授权

chown -R mysql .
chgrp -R mysql .

6.初始化

bin/mysqld --initialize --user=mysql --basedir=/u01/mysql --datadir=/u01/mysql/mysql-files

# 生成初始密码
...
2016-07-04T02:15:36.466820Z 1 [Note] A temporary password is generated for root@localhost:>kieDo)a8ka&

7.设置加密连接

bin/mysql_ssl_rsa_setup #在datadir目录下生成pem结尾文件
[ERROR]Failed to access directory pointed by --datadir.Please make sure that directory exists and is accessible by mysql_ssl_rsa_setup.Supplied value : /var/lib/mysql修改 /etc/my.cnf --datadir 属性
#/etc/my.cnf[mysqld]basedir=/u01/mysqldatadir=/u01/mysql/mysql-filessocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0character_set_server=utf8 #设置编码格式,否则出现中文乱码
8.加入系统服务

cp /u01/mysql/support-files/mysql.server /etc/init.d/mysqld
修改 mysqld 文件里的 basedir datadir 属性
chkconfig mysqld on # 设置开机自启动
chkconfig --list | grep mysqld
9.启动 重启 停止

service mysqld start
service mysqld restart
service mysqld stop
10.设置环境变量

# 把/u01/mysql/bin放入环境变量
vi /etc/profile
export PATH=$PATH:/u01/mysql/bin
可以改成 echo 'export PATH=$PATH:/u01/mysql/bin' >> /etc/profile
source /etc/profile

11. 登录

mysql -uroot -p 
输入刚才生成的密码
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)修改 /etc/my.cnf socket=/tmp/mysql.sock 并重启服务


12.登录成功,修改初始密码

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码SET PASSWORD FOR 'root'@'localhost'=PASSWORD('newpassword');