Centos 7インストールMysql 5.7実録(yum+rpm+ソースコード)

15055 ワード

Centos 7.xバージョン下針によるMysqlのインストールと使用は、以前のCentos 6以前のバージョンとは多少異なり、くだらないことは言うまでもありませんが、centos 7.x環境にmysql 5.7をインストールする方法をいくつかご紹介します
一、yum方式取付
CentOS 7.0のリリース以降、yumソースではMySQLの代わりにMariadbを使用してインストールが開始されています.yum install-y mysqlと入力しても、Mariadbのインストール内容が表示されます.ソースコードを使用してコンパイルインストールを行うのは面倒です.そのため、yumを使ってMySQLをインストールするには、公式に指定されたyumソースをダウンロードする必要があります.yumのダウンロード先は次のとおりです.https://dev.mysql.com/downloads/repo/yum/、ページの下に表示されるyumダウンロードアドレスは最新のmysql 8.0バージョンで、私たちが望んでいるmysql 5.7バージョンではありません.私たちはアクセスできます.https://repo.mysql.com/yum/ああ、このページにはmysqlの多くのバージョン(5.5,5.6,5.7,8.0)が含まれています.ディレクトリmysql-5.7-community/el/7/x 86に入ります.64/では、ページの一番下に来ると必要なmysql 57-community-release-el 7-10.noarch.rpmが見つかり、直接ダウンロードをクリックすればよい.
1.    MySQL Yum   
[root@mysql ~]# yum localinstall -y https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

2.  MySQLl5.7
[root@mysql ~]# yum install -y mysql-community-server

3.  MySQL    MySQL     
[root@mysql ~]# systemctl start mysqld.service
[root@mysql ~]# systemctl enable mysqld.service

4.    
  MySQL 5.7                   !       ,                      ,
       /var/log/mysqld.log   ,              :
[root@mysql ~]# cat /var/log/mysqld.log|grep 'A temporary password'
2019-06-04T07:02:32.856059Z 1 [Note] A temporary password is generated for root@localhost: :gaIl>rst9r%
           :gaIl>rst9r%      。
       MySQL:
[root@mysql ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26

Copyright (c) 2000, 2019, 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> 

                ,        ,        :
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

            (   123456       ):
mysql> set password=password("123456");
  
mysql> alter user 'root'@'localhost' identified by '123456';

    
mysql> flush privileges;
=======================================================================

       set password=password("123456");          :
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    :
   Mysql       validate_password_policy    ,validate_password_policy   0、1、2   :
0 or LOW       Length
1 or MEDIUM    Length; numeric, lowercase/uppercase, and special characters
2 or STRONG    Length; numeric, lowercase/uppercase, and special characters; dictionary

      1,    ,       ,       ,    。
                ,       ,       ,    。

   ,        ,           ,   ,     root    123456。
          :
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

         ,          。
======================================================================

    :
mysql5.7       mysql.user      password     ,password     authentication_string。
           :

mysql> update mysql.user set authentication_string=password('durant@123') where user='root';     
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 
=======================================================================

  mysql  
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.26    |
+-----------+
1 row in set (0.00 sec)

mysql> 
=======================================================================

  mysql5.7    latin1 utf8

    :
mysql> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.01 sec)

mysql> 

    :
[root@mysql ~]# cat /etc/my.cnf
......
[mysqld]
......
character-set-server=utf8                //        default-character-set=utf8,     5.7  mysql    

[client]
default-character-set=utf8

[root@mysql ~]# systemctl restart mysqld.service
[root@mysql ~]# mysql -p
......
mysql> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.02 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql> 

二、RPMパッケージ方式のインストール
1.        mysql mariadb-lib
[root@mysql ~]# /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
[root@mysql ~]# /bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps

2.  mysql5.7.25rpm   
    :https://downloads.mysql.com/archives/community/,                   mysql  ,    5.7.25
[root@mysql soft]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
[root@mysql soft]# tar -xvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
[root@mysql soft]# ll
total 1031284
-rw-r--r--. 1 root root  528015360 Jun  4 22:25 mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415  25402568 Dec 24 13:42 mysql-community-client-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    280904 Dec 24 13:42 mysql-community-common-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   3839640 Dec 24 13:42 mysql-community-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  46782224 Dec 24 13:42 mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  24079656 Dec 24 13:42 mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 130149460 Dec 24 13:42 mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2271668 Dec 24 13:42 mysql-community-libs-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2116628 Dec 24 13:42 mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 173130520 Dec 24 13:42 mysql-community-server-5.7.25-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 119947432 Dec 24 13:43 mysql-community-test-5.7.25-1.el7.x86_64.rpm

    (        ,       )       
[root@mysql soft]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
[root@mysql soft]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
[root@mysql soft]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
[root@mysql soft]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

=======================================================================
     mysql-community-server-5.7.25-1.el7.x86_64.rpm         :
[root@mysql soft]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        libaio.so.1()(64bit) is needed by mysql-community-server-5.7.25-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.25-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.25-1.el7.x86_64
        
            libaio  net-tools :

  libaio-0.3.107-10.el6.x86_64.rpm 
[root@mysql soft]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
[root@mysql soft]# rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm --force

  net-tools 
[root@mysql soft]# yum install net-tools 
=======================================================================

  rpm      mysql,       :
     
/var/lib/mysql/
 
    
/usr/share/mysql(mysql.server       )
/etc/my.cnf
 
    
/usr/bin(mysqladmin mysqldump   )
 
    
/etc/rc.d/init.d/(      mysql   )

3.       
                   mysql     ,      root      mysql   ,            
[root@mysql ~]# mysql_install_db --datadir=/var/lib/mysql      //    datadir,      ~/.mysql_secret    
[root@mysql ~]# mysqld --initialize --user=mysql    //        ,     /var/log/mysqld.log      。    mysql    ,     --user  。

4.  mysql               ,    mysql   
[root@mysql ~]# chown -R mysql:mysql /var/lib/mysql
[root@mysql ~]# systemctl start mysqld.service

5.   3        mysql,  root     ,   mysql                      

  --initialize      “  ”      ,    root                   ,              ,
   --initialize-insecure          ,     root         。 

       --initialize    ,      root     ,   log   ,     "K/mEs9*+qx3K"       root  
[root@mysql ~]# cat /var/log/mysqld.log
......
2019-06-04T14:58:06.047280Z 1 [Note] A temporary password is generated for root@localhost: K/mEs9*+qx3K

[root@mysql ~]# mysql -p'K/mEs9*+qx3K'
mysql> set password=password('durant@123');
mysql> flush privileges;

三、コンパイル方式のインストール
1.        mysql mariadb-lib
[root@mysql ~]# /bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
[root@mysql ~]# /bin/rpm -e $(/bin/rpm -qa | grep mariadb|xargs) --nodeps

2.      
[root@mysql ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel

3.  boost
[root@mysql ~]# mkdir -p /usr/local/boost
[root@mysql ~]# cd /usr/local/boost/
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@mysql boost]# tar -zxvf boost_1_59_0.tar.gz

4.    mysql5.7.25
[root@mysql ~]# groupadd mysql
[root@mysql ~]# useradd -g mysql mysql -M -s /sbin/nologin
[root@mysql ~]# cd /usr/local/src/
[root@mysql src]# wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.25.tar.gz
[root@mysql src]# tar -zxvf mysql-5.7.25.tar.gz
[root@mysql src]# cd mysql-5.7.25
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/usr/local/boost

[root@mysql mysql-5.7.25]#  make && make install

5.  /data/mysql  
[root@mysql mysql-5.7.25]# mkdir -p /data/mysql/data
[root@mysql mysql-5.7.25]# chown -R mysql:mysql /data/mysql

6.         ,            
[root@mysql mysql]# /data/mysql/bin/mysqld --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql --initialize
2019-06-05T07:34:25.320446Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-05T07:34:25.568345Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-05T07:34:25.597709Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-05T07:34:25.664702Z 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: 58228129-8764-11e9-b105-000c29b1fba8.
2019-06-05T07:34:25.667573Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-05T07:34:25.672622Z 1 [Note] A temporary password is generated for root@localhost: L->08o4UgOcV

      ,                 ,   'L->08o4UgOcV',         ,
      --innodb_data_file_path=ibdata1:1G:autoextend  。

7.  my.cnf,    ,    ,    
vim /etc/my.cnf

[client]
default-character-set=utf8
socket = /data/mysql/var/mysql.sock

[mysqld]
port = 33306
socket = /data/mysql/var/mysql.sock

basedir = /data/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/data/mysql.pid
user = mysql
innodb_buffer_pool_size = 1536M
innodb_log_file_size = 512M
query_cache_size = 0
slow_query_log = 1
long_query_time = 2
slow_query_log_file = /data/mysql/data/mysql-slow.log
log_error = /data/mysql/data/mysql-error.log
max_allowed_packet = 2048M
max_connections = 2000
open_files_limit = 10240
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
binlog_format = row
transaction-isolation = Read-Committed
skip-name-resolve
lower_case_table_names = 1

default-time-zone = '+8:00'
event_scheduler = ON
group_concat_max_len = 102400
local-infile=0
skip_symbolic_links=yes

[mysql]
default-character-set=utf8

8.  mysql  
[root@mysql ~]# cd /data/mysql
[root@mysql mysql]# mkdir var
[root@mysql mysql]# chown -R mysql:mysql var
[root@mysql mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mysql mysql]# systemctl enable mysqld
[root@mysql mysql]# systemctl start mysqld

9.      
[root@mysql mysql]# echo "export PATH=$PATH:/data/mysql/bin" >> /etc/profile
[root@mysql mysql]# source /etc/profile

10.  mysql  
     mysql     L->08o4UgOcV,            (       ),        。
[root@mysql mysql]# mysql -p'L->08o4UgOcV'
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql mysql]# mysql -p

mysql> set password=password('durant@123');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

参考記事:https://www.cnblogs.com/kevingrace/p/8340690.html