centos7安裝mysql5.7(tar.gz)

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> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章