概述
1.安装准备
mysql安装文件,从官网下载目标版本文件或者使用此处提供的mysql
链接:https://pan.baidu.com/s/1chV8t53kDvK8s9uK_r9Cdw
提取码:5lsx
2.安装
①
将文件传入到centos7中并解压改名
[root@localhost develop]# pwd
/usr/local/develop
[root@localhost develop]# ls
jdk1.8.0_241 mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz tomcat
[root@localhost develop]# tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@localhost develop]# ls
jdk1.8.0_241 mysql-5.7.29-linux-glibc2.12-x86_64 mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz tomcat
[root@localhost develop]# rm -rf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@localhost develop]# mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql
[root@localhost develop]# ls
jdk1.8.0_241 mysql tomcat
②
安装libaio
yum install -y libaio
yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel
③
添加mysql组,mysql用户并查看
[root@localhost develop]# groupadd mysql
[root@localhost develop]# useradd -r -g mysql mysql
[root@localhost develop]# id mysql
uid=997(mysql) gid=1000(mysql) groups=1000(mysql)
④
修改目录拥有者为mysql
[root@localhost mysql]# pwd
/usr/local/develop/mysql
[root@localhost mysql]# chown -R mysql:mysql ./
⑤
初始化数据库并创建RSA private key
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/develop/mysql --datadir=/usr/local/develop/mysql/data
2020-04-09T13:01:15.555819Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-09T13:01:16.575583Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-04-09T13:01:16.694257Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-09T13:01:16.762183Z 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: 32e74233-7a62-11ea-b022-00163e0ea2e1.
2020-04-09T13:01:16.765282Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-04-09T13:01:17.319979Z 0 [Warning] CA certificate ca.pem is self signed.
2020-04-09T13:01:17.553291Z 1 [Note] A temporary password is generated for root@localhost: p95w4k#EkXjp
注意记录最后的生成的随机密码p95w4k#EkXjp,忽略warning
创建RSA private key
bin/mysql_ssl_rsa_setup --datadir=/usr/local/develop/mysql/data
⑥
修改data目录拥有者为mysql用户
[root@localhost mysql]# pwd
/usr/local/develop/mysql
[root@localhost mysql]# chown -R mysql:mysql data
⑦
编辑配置my.cnf文件
[root@localhost mysql]# vim /etc/my.cnf
内容为:
[mysqld]
character_set_server=utf8
#跳过密码验证
#skip-grant-tables
init_connect='SET NAMES utf8'
basedir=/usr/local/develop/mysql
datadir=/usr/local/develop/mysql/data
socket=/tmp/mysql.sock
lower_case_table_names = 1
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/usr/local/develop/mysql/data/mysqld.pid
⑧
添加开机启动
添加开机启动
[root@localhost mysql]# cp /usr/local/develop/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
mysqld被编辑的内容:
basedir=/usr/local/develop/mysql/
datadir=/usr/local/develop/mysql/data
⑨
启动mysql
使用
systemctl start mysqld 或者 service mysqld start
[root@localhost mysql]# service mysqld start
Starting MySQL. [ OK ]
加入开机启动
systemctl enable mysqld
⑩
添加软连接
[root@localhost mysql]# ln -s /usr/local/develop/mysql/bin/mysql /usr/bin
⑪
登录
登录时输入的用户密码为之前随机生成的密码
[root@localhost mysql]# mysql -uroot -p
Enter password:
万一忘记密码,可以通过跳过密码验证的方式进入:
编辑my.cnf
vim /etc/my.cnf
将
#skip-grant-tables
前面的"#"去除
重启mysql
[root@localhost bin]# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
直接输入mysql即可登录
[root@localhost bin]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
⑫
修改密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=password("root") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
mysql> quit;
注意:update user set authentication_string=password(“用户密码”) where user=“root”; 中authentication_string为mysql5.7之后出现的字段,mysql5.7之前请使用
update user set password=password("root") where user="root";
编辑my.cnf
vim /etc/my.cnf
将
skip-grant-tables
注释掉,并且再次重启mysql
再次登录即可
[root@localhost bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.29
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
最后
以上就是难过蜜蜂为你收集整理的centos7安装mysql5.7(tar.gz)1.安装准备2.安装的全部内容,希望文章能够帮你解决centos7安装mysql5.7(tar.gz)1.安装准备2.安装所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复