Mysql5.7版本:Linux - Generic (glibc 2.12) (x86, 64-bit)
Mysql5.7地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
系统:Linux Cent7.0
安装步骤:
(1)、安装
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
(2)、授权
cd /usr/local/src
chown -R mysql:mysql ./
(3)创建数据库 初始化表配置
bin/mysqld --initialize --user=mysql --basedir=/usr/local/src/mysql --datadir=/usr/local/src/mysql/data
注:Mysql5.7之前使用的是 script/mysql_install_db --user=mysql --basedir=/usr/local/src/mysql --datadir=/usr/local/src/mysql/data
(4)修改当前目录拥有者为root用户
chown -R root:root ./
(5)修改当前data目录拥有者为mysql用户
chown -R mysql:mysql data
(6)创建配置文件
cp support-files/my-default.cnf /etc/my.cnf
注:此文件下如果没有my-default.cnf 自行创建,如果有忽略
配置文件内容地址:https://blog.csdn.net/djcode/article/details/78621772
(7)添加开机启动
cp support-files/mysql.server /etc/init.d/mysql
service mysql start
(8)添加环境变量
vi /etc/profile
在里面加入:export PATH=$PATH:/usr/local/src/mysql:/usr/local/src/mysql/bin
注:不想加的 自己建立长连接去 走开
(9)开启mysql
mysql -uroot -pk?_!v5jfePrt
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
注:MYSQL编译过程中会自动生成一个密码 然而并没有什么用 重置密码
重置1:
vim /etc/my.cnf 加入skip-grant-tables
重置2
service mysql restart
重置3
mysql -uroot
注:无密码进入
重置4
update mysql.user set authentication_string=password('root') where user='root' ;
注:注意字段不是password 同志醒醒了
重置5
编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录
重置6
mysql -u root -p
可以了……
另外,如果密码过期了,请移步:https://blog.csdn.net/qq_34206560/article/details/81062731