MySQL basic study notes-install MySQL database

Install MySQL database

1. Download of MySQL

Download link: http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

Choice: mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar (other suitable versions can also be selected)


2. Installation under Linux platform

  • Prerequisite work: uninstall mariadb
[root@mysql ~]# yum remove mysql-libs -y
  • Unzip mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar:
[root@mysql ~]# tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-common-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-test-5.7.31-1.el7.x86_64.rpm
  • Install the RPM package:

Because there are some dependencies between packages, they need to be installed in a certain order:

  1. mysql-community-common-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-common-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-common-5.7.31-1.e################################# [100%]
    
  2. mysql-community-libs-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-libs-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-5.7.31-1.el7################################# [100%]
    
  3. mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-compat-5.7.3################################# [100%]
    
  4. mysql-community-client-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-client-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-client-5.7.31-1.e################################# [100%]
    
  5. mysql-community-server-5.7.31-1.el7.x86_64.rpm

    [root@mysql ~]# rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-server-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    错误:依赖检测失败:
            /usr/bin/perl 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            net-tools 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            perl(Getopt::Long) 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
            perl(strict) 被 mysql-community-server-5.7.31-1.el7.x86_64 需要
    

    Perl and net-tools are required, just install it:

    [root@mysql ~]# yum install perl net-tools -y
    

    After the dependency is installed, you can install it:

    [root@mysql ~]# rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
    警告:mysql-community-server-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-server-5.7.31-1.e################################# [100%]
    
  • Start MySQL:
[root@mysql ~]# systemctl start mysqld			#启动服务
[root@mysql ~]# systemctl enable mysqld			#开机自启
[root@mysql ~]# systemctl status mysqld			#查看状态
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2020-09-21 20:12:15 CST; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 3278 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─3278 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

9月 21 20:12:13 mysql systemd[1]: Starting MySQL Server...
9月 21 20:12:15 mysql systemd[1]: Started MySQL Server.
  • Log in to MySQL:

The version after MySQL 5.7 removes the empty password of the root user during the default installation. When logging in for the first time, the system will generate a temporary root password, which can be viewed through /var/log/mysqld.log :

[root@mysql ~]# cat /var/log/mysqld.log | grep "password"
2020-09-21T12:12:13.721817Z 1 [Note] A temporary password is generated for root@localhost: Qqfpoxet1+p(
# 初始密码为:Qqfpoxet1+p(
[root@mysql ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31

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>

Among them, mysql represents the client command, "-u" is followed by the database user, and "-p" represents the password that needs to be entered. At the same time, the welcome interface also explains the following parts:

  • Commands end with; or \g. Commands end with ";" or "\g"
  • Your MySQL connection id is 2 The connection ID of the client. This number records the number of connections made by the MySQL service so far; each new connection will automatically add 1
  • Server version: 5.7.31 MySQL server version and type
  • Type'help;' or'\h' for help. Type'\c' to clear the current input statement. Use "help;" or "\h" to display the help content; use "\c" to clear the command line cache

However, the temporary password cannot perform most operations, such as:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.		
#提示要使用 ALTER USER 来修改初始密码
  • change Password:
mysql> alter user 'root'@'localhost' identified by 'Opfordream@0518';
Query OK, 0 rows affected (0.00 sec)
  • Set the root user to log in remotely:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Opfordream@0518' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • Configure MySQL:
[root@mysql ~]# vim /etc/my.cnf
#增加如下内容
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[root@mysql ~]# systemctl restart mysqld	#重启 MySQL
  • Test the remote connection:

It is recommended to turn off the firewall on the server side first:

[root@mysql ~]# systemctl stop firewalld
[root@mysql ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Test the remote connection:

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_36879493/article/details/108719480