Linux Centos7.5 安装 mysql-8.0.15

mysql有两种安装方式:源码包安装和二进制包安装

本文描述的是二进制安装包,下载目录:https://dev.mysql.com/downloads/mysql/

选择对应位数的文件下载 ~ 

文件放置至 /home 路径

1、解压到/usr/local/目录下
[root@centos7.5  /]# cd home
[root@centos7.5  home]# ls
mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
[root@centos7.5  home]#  tar xf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz -C /usr/local/

2、目录/usr/lcoal/下创建链接
[root@centos7.5  /]# cd usr/local/
[root@centos7.5  local]#  ln -sn mysql-8.0.15-linux-glibc2.12-x86_64 mysql

3、创建mysql用户和所属组
[root@centos7.5  ~]# groupadd mysql
[root@centos7.5  ~]# useradd -r -g mysql mysql

4、设置/usr/local/mysql目录下所有文件为root主,mysql组
[root@centos7.5  /]# cd usr/local/mysql/
[root@centos7.5  mysql]# chown -R root.mysql ./*

5、创建目录存放mysql数据
[root@centos7.5  mysql]# mkdir -pv /data/mysql

6、修改/data/mysql/目录的属主属组为mysql
[root@centos7.5  mysql]# chown -R mysql.mysql /data/mysql/

7、编辑环境变量
[root@centos7.5  mysql]# vim /etc/profile.d/mysql.sh
i 进入编辑模式
输入 export PATH=/usr/local/mysql/bin:$PATH
esc按键 :wq 保存并退出

8、重新加载mysql.sh文件
[root@centos7.5  mysql]# . /etc/profile.d/mysql.sh

9、初始化mysql 
[root@centos7.5  mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
***记下生成的密码 ,若不生成密码,设置空密码:--initialize后加-insecure

10、创建etc目录,将/etc/my.cnf复制到/usr/local/mysql/etc目录下
[root@centos7.5  mysql]# mkdir etc
[root@centos7.5  mysql]# cp /etc/my.cnf etc/

11、编辑/usr/local/mysql/etc.cnf
[root@centos7.5  mysql]# cd etc/
[root@centos7.5  etc]# vim my.cnf 
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/var/run/mysql/mysql.pid

#
# include all files from the config directory
#
!includedir /usr/local/mysql/etc/my.cnf.d

esc按键 :wq 保存并退出

12、根据my.cnf文件路径配置,创建mysql目录下对应的目录和文件
[root@centos7.5  etc]# mkdir my.cnf.d

13、创建logs目录
[root@centos7.5  mysql]# mkdir logs

14、设置目录所属主,所属组
[root@centos7.5  mysql]# chown -R root.mysql logs

15、创建错误日志文件
[root@centos7.5  logs]# touch error.log

16、设置错误日志所属主和所属组
[root@centos7.5  logs]# chown -R mysql.mysql error.log

17、将目录/usr/local/mysql/support-files/mysql.server复制到目录/etc/init.d/mysqld
[root@centos7.5  support-files]#  cp mysql.server /etc/init.d/mysqld

18、启动脚本
[root@centos7.5  etc]# service mysqld start
Starting MySQL.

19、登录(/usr/local或/data目录下)设置密码
[root@centos7.5  local]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.15 MySQL Community Server - GPL

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> set password='123456

Query OK, 0 rows affected (0.01 sec)

mysql> quit;

--------------------OK!ヾ(o◕∀◕)ノヾ 已安装成功!--------------------

如果使用navicat连接数据库出现异常
[ERROR 1130: Host 'xxx.xxx.xxx.xxx' is not allowed to connect to thisMySQL server ]
更新user表权限可能会帮到你哦~

mysql> select host,user,plugin from user where user = 'root';
+-----------+------+-----------------------+
| host      | user | plugin                |
+-----------+------+-----------------------+
| localhost | root | caching_sha2_password |
+-----------+------+-----------------------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql>  flush privileges;
mysql> select host,user,plugin from user where user = 'root';
+------+------+-----------------------+
| host | user | plugin                |
+------+------+-----------------------+
| %    | root | caching_sha2_password |
+------+------+-----------------------+
1 row in set (0.00 sec)

--------------------OK!ヾ(o◕∀◕)ノヾ 已配置成功!--------------------
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值