Linux环境MySQL5.7的安装

一、安装前准备

1、检查是否已经安装过mysql,执行命令

rpm -qa | grep mysql

已安装的情况(如何卸载不做细述):
在这里插入图片描述

注意:
细节注意:

检查一下系统是否存在 mariadb 数据库,如果有,一定要卸载掉,否则可能与 mysql 产生冲突。
检查是否安装了 mariadb:[root@rabbitmq2~]# rpm -qa | grep mariadb
如果有就使劲卸载干净:

systemctl stop mariadb
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-5.5.52-1.el7.x86_64
rpm -e --nodeps mariadb-server-5.5.52-1.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

未安装的情况:
在这里插入图片描述

2、检查mysql用户组和用户是否存在,如果没有,则创建

cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
#创建账号
groupadd mysql
useradd -r -g mysql mysql

3、从官网下载是用于Linux的Mysql安装包

下载地址
或是使用命令下载:

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

二 、安装Mysql

1、解压安装包

在执行wget命令的目录下或你的上传目录下找到Mysql安装包:mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz 执行解压命令:

tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

解压完成后,可以看到当前目录下多了一个解压文件,移动该文件到/usr/local/下,并将文件夹名称修改为mysql。

mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql

2、在/usr/local/mysql目录下创建data目录

mkdir /usr/local/mysql/data

3、更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限

chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

4、编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

A temporary password is generated for root@localhost: li<H;!f6r.<e

[root@taofadeng mysql]# cd /usr/local/mysql/bin
[root@taofadeng bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2020-05-08T08:26:10.258488Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-08T08:26:11.521150Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-08T08:26:11.801945Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-08T08:26:11.888838Z 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: 93363347-9105-11ea-8543-64006a0e099c.
2020-05-08T08:26:11.921511Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-08T08:26:12.592856Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-08T08:26:12.758482Z 1 [Note] A temporary password is generated for root@localhost: li<H;!f6r.<e

记录日志最末尾位置root@localhost:后的字符串,此字符串为mysql管理员临时登录密码。

5、编辑配置文件my.cnf,添加配置如下(忽略)

# # vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

可能需要手动创建以下文件:
/var/lib/mysql/mysql.sock
/var/log/mariadb/mariadb.log

6、启动mysql服务器

/usr/local/mysql/support-files/mysql.server start

启动MySQL

[root@taofadeng bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/taofadeng.err'.
 SUCCESS! 
[root@taofadeng bin]# mysql -u root -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> 

修改root默认密码:

mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

开放远程连接

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 user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql> 

7、添加软连接,并重启mysql服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart

8、设置开机启动

1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值