1.解压
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
2.移动并将解压文件夹改名/data1/mysql5.7.29下(注:数据存储在/data1目录下)
mv mysql-5.7.29-linux-glibc2.12-x86_64 /data1/mysql5.7.29
3.再创建用户和用户组
groupadd mysql
useradd -r -g mysql mysql
4.在mysql目录中创建三个目录
cd /data1/mysql5.7.29
mkdir data mysql_log mysql_pid
touch /data1/mysql5.7.29/mysql_log/mysql.log
touch /data1/mysql5.7.29/mysql_pid/mysql.pid
5.更改文件的权限
chown -R mysql.mysql /data1/mysql5.7.29
6.关于my.cnf的配置
[root@localhost] vi /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir= /data1/mysql5.7.29
datadir= /data1/mysql5.7.29/data
socket=/tmp/mysql.sock
log-error=/data1/mysql5.7.29/mysql_log/mysql.log
pid-file=/data1/mysql5.7.29/mysql_pid/mysql.pid
character_set_server=utf8
symbolic-links=0
[mysql]
default-character-set = utf8
[mysqld_safe]
!includedir /etc/my.cnf.d
7.初始化数据库
/data1/mysql5.7.29/bin/mysqld
--user=mysql
--basedir=/data1/mysql5.7.29
--datadir=/data1/mysql5.7.29/data
--initialize
密码保存路径:/data1/mysql5.7.29/mysql_log/mysql.log文件中,如下图:
cat /data1/mysql5.7.29/mysql_log/mysql.log
2021-10-22T06:36:02.581231Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-22T06:36:03.515804Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-22T06:36:03.754344Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-22T06:36:03.891926Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 544ce401-3302-11ec-a85d-702084302102.
2021-10-22T06:36:03.907816Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-22T06:36:04.607437Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-22T06:36:04.837732Z 1 [Note] A temporary password is generated for root@localhost: -M(0+ThNqEok
8.设置mysql开机自启
cp /data1/mysql5.7.29/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig
9.启动mysql(如果遇到异常,请确认data, mysql_log, mysql_pid的文件权限)
service mysql start
10.登录(密码在步骤7)
/data1/mysql5.7.29/bin/mysql -uroot -p
11.修改密码(引号内设置自己的密码)
set password=password("**自己的密码**");
flush privileges;
12.设置远程连接
grant all privileges on *.* to 'root'@'%'identified by '** 自己的密码**' with grant option;
flush privileges;
13.再次查询用户表命令:
use mysql;
select User,authentication_string,Host from user;
+---------------+-------------------------------------------+-----------+
| User | authentication_string | Host |
+---------------+-------------------------------------------+-----------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % |
+---------------+-------------------------------------------+-----------+
14.如果mysql远程还是连接不上,请检查防火墙是否关闭!(centos7)
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
15.关于Mysql登录密码错误的处理
vi/etc/my.cnf
skip-grant-tables # [mysqld]下添加该项,然后重启mysql : service mysql restart 然后进入mysql
mysql> flush privileges;
ERROR 1290 (HY000): The MySQL server is running withthe --skip-grant-tables option so it cannot execute this statement
mysql> set password for root@localhost=password('**密码**');
mysql> flush privileges;
再注销# skip-grant-tables
再重启mysql