【数据库MySQL】数据库的安装

一、RPM包安装

1、先从官网下载RPM安装包,再上传至服务器:

2、查看是否上传:

[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、解压并查看:

[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、安装并首先限制mariadb相关软件包:

[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、启动服务并查看状态:

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

6、登录数据库

  ①获取数据库初始密码:

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

   ②登录:

[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

二、通用二进制格式安装

    1、从网站下载glibc版本的Mysql并上传至服务器:

 2、新建用户以安全方式运行进程:

[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、安装并初始化mysql :

     ①安装

[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/*                                //更改权限

    ②初始化:

[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、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、mysql提供sysv服务脚本:

[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、启动mysql:

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

7、mysqlbin目录加入PATH环境变量,编辑/etc/profile文件:

[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、登录数据库:

[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> 

三、修改数据库密码

[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> 

 

猜你喜欢

转载自blog.csdn.net/trichloromethane/article/details/112483256