Linux 系统安装 MySQL8.0.18

一、安装方式

采取从第三方镜像下载MySQL8.0.18的压缩包的方式手动安装。
镜像地址:https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/

二、安装步骤

1.将下载好的 mysql-8.0.18-el7-x86_64.tar.gz 通过 FinalShell 上传到服务器的目录,我放在 /home/zhjt

2.解压缩并改名为mysql

[zhjt@localhost ~]$ tar -zxvf mysql-8.0.18-el7-x86_64.tar.gz
[zhjt@localhost ~]$ mv mysql-8.0.18-el7-x86_64 mysql

3.创建mysql用户组及用户,并给mysql用户设置密码

[zhjt@localhost ~]# groupadd mysql
[zhjt@localhost ~]# useradd -r -g mysql mysql
[zhjt@localhost ~]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:123qweGHJ
重新输入新的 密码:123qweGHJ
passwd:所有的身份验证令牌已经成功更新。

4.添加mysql配置文件:(/etc/my.cnf

[zhjt@localhost ~]# vim /etc/my.cnf

内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /home/zhjt/mysql
datadir = /home/zhjt/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-error = /home/zhjt/mysql/data/error.log
pid-file = /home/zhjt/mysql/data/mysql.pid

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

然后保存退出。

5.在mysql目录下新建data文件夹用于存放数据库文件

[zhjt@localhost mysql]# mkdir data

6.在mysql当前目录下设定目录的访问权限(注意后面的小点,表示当前目录)

[zhjt@localhost mysql]# chown -R mysql .
[zhjt@localhost mysql]# chgrp -R mysql .

7.初始化数据库

[zhjt@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/home/zhjt/mysql --datadir=/home/zhjt/mysql/data

打开日志文件,找到初始密码:

[zhjt@localhost mysql]# /home/zhjt/mysql/data/error.log

Linux 系统安装 MySQL8.0.18_第1张图片

8. 启动mysql

[zhjt@localhost mysql]# ./support-files/mysql.server start
Starting MySQL............ SUCCESS! 

9.登录mysql,修改root用户密码

[zhjt@localhost mysql]# ./bin/mysql -uroot -p
Enter password: 4t?iQnB,+5co
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17

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> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.03 sec)

10.配置mysql允许远程访问

创建远程登录对象: CREATE USER 'root'@'%' IDENTIFIED BY '123456';
授权远程登录: grant all privileges on *.* to 'root'@'%' with grant option;
强制刷新: flush privileges;

mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

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

11.mysql启动、停止、重启命令

[zhjt@localhost mysql]# ./support-files/mysql.server start
Starting MySQL.. SUCCESS! 
[zhjt@localhost mysql]# ./support-files/mysql.server restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[zhjt@localhost mysql]# ./support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!

三、参考文档

https://blog.csdn.net/u010476739/article/details/100083959

你可能感兴趣的:(服务器)