[Database MySQL] Database installation

One, RPM package installation

1. Download the RPM installation package from the official website and upload it to the server:

2. Check whether to upload:

[root@bogon ~]# ls -l mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 root root 569344000 1月  11 15:06 mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar

3. Unzip and view:

[root@bogon ~]# tar xf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
[root@bogon ~]# ls -l mysql-community*
-rw-r--r--. 1 7155 31415  25012200 7月  14 2016 mysql-community-client-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415    277608 7月  14 2016 mysql-community-common-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   3770552 7月  14 2016 mysql-community-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  45366572 7月  14 2016 mysql-community-embedded-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  23925764 7月  14 2016 mysql-community-embedded-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 125630688 7月  14 2016 mysql-community-embedded-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2235496 7月  14 2016 mysql-community-libs-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415   2112812 7月  14 2016 mysql-community-libs-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  51288740 7月  14 2016 mysql-community-minimal-debuginfo-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 158947688 7月  14 2016 mysql-community-server-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415  14021340 7月  14 2016 mysql-community-server-minimal-5.7.14-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 116741256 7月  14 2016 mysql-community-test-5.7.14-1.el7.x86_64.rpm

4. Install and first restrict mariadb related packages:

[root@bogon ~]# yum remove mariadb-libs
[root@bogon ~]# yum  install -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm mysql-community-common-5.7.14-1.el7.x86_64.rpm mysql-community-libs-5.7.14- 1.el7.x86_64.rpm mysql-community-server-5.7.14-1.el7.x86_64.rpm

5. Start the service and check the status:

[root@bogon ~]# systemctl start mysqld
[root@bogon ~]# systemctl enable mysqld
[root@bogon ~]# systemctl is-active mysqld
active

6. Log in to the database

  ①Get the initial password of the database:

[root@bogon ~]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log
Ws-OZH#gl8pq

   ②Login:

[root@bogon ~]# 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.14

Copyright (c) 2000, 2016, 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> \q
Bye

 

Two, universal binary format installation

    1. Download the glibc version of Mysql from the website and upload it to the server:

 2. Create a new user to run the process in a safe way:

[root@bogon ~]# groupadd -r -g 306 mysql                        //添加用户组
[root@bogon ~]# useradd -r -g 306 -u 306 mysql                  //添加用户
[root@bogon ~]# id mysql                                        //查看用户信息
uid=306(mysql) gid=306(mysql) 组=306(mysql)

3. Install and initialize mysql:

     ① Installation

[root@bogon ~]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local     //解压
[root@bogon ~]# cd /usr/local
[root@bogon local]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz            //二次解压
[root@bogon local]# ln -s mysql-5.7.14-linux-glibc2.5-x86_64 mysql              //制作软链接
[root@bogon local]# chown -R mysql.mysql mysql/*                                //更改权限

    ② Initialization:

[root@bogon local]# mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2021-01-11T09:51:52.940057Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-11T09:51:53.235501Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-11T09:51:53.285861Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-11T09:51:53.348995Z 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: a234c25a-53f2-11eb-83bc-000c29190c65.
2021-01-11T09:51:53.349625Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-11T09:51:53.364186Z 1 [Note] A temporary password is generated for root@localhost: 2QixadqkpG.o     //此处标记数据库初始密码

4. Provide the main configuration file for mysql :

[root@bogon local]# cd /usr/local/mysql 
[root@bogon mysql]# \cp support-files/my-default.cnf /etc/my.cnf 
[root@bogon mysql]# vim /etc/my.cnf 
添加如下行指定mysql数据文件的存放位置: 
 datadir = /usr/local/mysql/data

5. Provide sysv service script for mysql :

[root@bogon mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld 
[root@bogon mysql]# chmod +x /etc/rc.d/init.d/mysqld

6. Start mysql:

[root@bogon bin]# chkconfig --add mysqld                      //添加为系统服务 
[root@bogon bin]# # chkconfig mysqld on                       //开机自启动 
[root@bogon bin]# systemctl start mysqld                      //启动mysql服务

7, the mysql 's bin directory added to PATH environment variable, edit the / etc / profile file:

[root@bogon mysql]# cd /etc/profile.d/
[root@bogon profile.d]# vim mysql.sh 

export PATH=$PATH:/usr/local/mysql/bin
                                         
[root@bogon profile.d]# source mysql.sh

8. Log in to the database:

[root@bogon profile.d]# 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.14

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

Three, modify the database password

[root@bogon profile.d]# mysqladmin -uroot -p'2QixadqkpG.o' password '123abcABC'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@bogon profile.d]# mysql -uroot -p'123abcABC'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.14 MySQL Community Server (GPL)

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

 

Guess you like

Origin blog.csdn.net/trichloromethane/article/details/112483256