一:源码安装
1.在官网下载好后将下载的MySQL上传到服务器
[root@localhost ynxx]# ll
总用量 756624
drwxr-xr-x. 7 10 143 245 7月 4 19:37 jdk1.8.0_221
-rw-r--r--. 1 root root 195094741 11月 21 00:28 jdk-8u221-linux-x64.tar.gz
-rw-r--r--. 1 root root 579686400 11月 21 00:36 mysql-8.0.18-1.el8.x86_64.rpm-bundle.tar
2.解压
[root@localhost ynxx]# tar xf mysql-8.0.18-1.el8.x86_64.rpm-bundle.tar
[root@localhost ynxx]# ll
总用量 1322740
drwxr-xr-x. 7 10 143 245 7月 4 19:37 jdk1.8.0_221
-rw-r--r--. 1 root root 195094741 11月 21 00:28 jdk-8u221-linux-x64.tar.gz
-rw-r--r--. 1 root root 579686400 11月 21 00:36 mysql-8.0.18-1.el8.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 12307740 9月 23 15:19 mysql-community-client-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 22301616 9月 23 15:19 mysql-community-client-debuginfo-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 615256 9月 23 15:20 mysql-community-common-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 2893980 9月 23 15:20 mysql-community-debuginfo-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 20198496 9月 23 15:20 mysql-community-debugsource-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 2090236 9月 23 15:20 mysql-community-devel-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 1462400 9月 23 15:20 mysql-community-libs-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 2020228 9月 23 15:20 mysql-community-libs-debuginfo-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 54321732 9月 23 15:21 mysql-community-server-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 20898836 9月 23 15:21 mysql-community-server-debug-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 93294068 9月 23 15:21 mysql-community-server-debug-debuginfo-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 190301696 9月 23 15:21 mysql-community-server-debuginfo-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 142439684 9月 23 15:22 mysql-community-test-8.0.18-1.el8.x86_64.rpm
-rw-r--r--. 1 7155 31415 14521988 9月 23 15:22 mysql-community-test-debuginfo-8.0.18-1.el8.x86_64.rpm
二:二进制安装
参考地址:https://blog.csdn.net/vkingnew/article/details/81267223
将下载好的二进制文件上传到服务器,可以看到这个版本采用了tar.xz的打包压缩方式
[root@localhost /]# cd mysql/
[root@localhost mysql]# ls
mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
解压
[root@localhost mysql]# tar -xJvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisamlog
。。。。。。。以下省略
[root@localhost mysql]#
移动 到mysql下
[root@localhost /]# mv /mysql/mysql-8.0.18-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@localhost /]# cd /usr/local/mysql
[root@localhost mysql]# ls
bin docs include lib LICENSE LICENSE.router man README README.router run share support-files var
配置参数文件
[root@localhost /]# vi /etc/my.cnf
[root@localhost /]# cat /etc/my.cnf
[mysqld]
server-id = 1
port = 3306
mysqlx_port = 33060
mysqlx_socket = /tmp/mysqlx.sock
datadir = /data/mysql
socket = /tmp/mysql.sock
pid-file = /tmp/mysqld.pid
log-error = error.log
slow-query-log = 1
slow-query-log-file = slow.log
long_query_time = 0.2
log-bin = bin.log
relay-log = relay.log
binlog_format =ROW
relay_log_recovery = 1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect ='SET NAMES utf8mb4'
innodb_buffer_pool_size = 1G
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_timestamps = SYSTEM
lower_case_table_names = 1
default-authentication-plugin =mysql_native_password
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
创建目录授权等
[root@localhost /]# mkdir -p /data/mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd mysql
useradd:mysql 组已经存在 - 如果您想将此用户加入到该组,请使用 -g 参数。
[root@localhost /]# useradd -g mysql mysql
[root@localhost /]# chown -R mysql:mysql /data/mysql/
[root@localhost /]# chmod -R 775 /data/mysql/
初始化数据库
官方推荐使用--initialize,在错误日志中生成难以输入的临时密码
[root@localhost /]# usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --initialize
[root@localhost /]# cat /data/mysql/error.log | grep -i password
2019-11-21T11:07:18.200635+08:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3g&W7SqLT9iR #密码
设置启动文件和环境变量:
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动数据库
[root@localhost /]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!
编辑配置
[root@localhost /]# vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
让配置生效
[root@localhost /]# source /etc/profile.d/mysql.sh
查看版本
[root@localhost /]# mysqld --version
/usr/local/mysql/bin/mysqld Ver 8.0.18 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
登录,密码为空不用输入直接回车
[root@localhost /]# /usr/local/mysql/bin/mysql -p -S /tmp/mysql.sock
Enter password: 3g&W7SqLT9iR
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 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>
查看版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18 |
+-----------+
1 row in set (0.00 sec)
.更改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
登录
[root@localhost /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.18 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>
20191121111743.png
连接报错,没有开放远程登录
开放远程登录
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 host = '%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
20191121111924.png
mysql 停止
[root@localhost /]# /etc/init.d/mysql stop
Shutting down MySQL... SUCCESS!
注意:登录后,操作报错,要重置密码。
错误
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改,即可
ALTER USER USER() IDENTIFIED BY '12345678'
网友评论