内容纲要
环境
- 阿里云 ECS 服务器:2 核 4 GB
- 100G 云盘
- 5M 带宽
- 服务器操作系统 CentOS 8.2
下载 mysql
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-8.0.15-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-8.0.15-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-8.0.15-1.el7.x86_64.rpm
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-8.0.15-1.el7.x86_64.rpm
或者 8.0.35
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-8.0.35-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-8.0.35-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-8.0.35-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm
https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-8.0.35-1.el7.x86_64.rpm
按顺序安装
yum -y localinstall mysql-community-common-8.0.15-1.el7.x86_64.rpm
yum -y localinstall mysql-community-libs-8.0.15-1.el7.x86_64.rpm
yum -y localinstall mysql-community-client-8.0.15-1.el7.x86_64.rpm
yum -y localinstall mysql-community-server-8.0.15-1.el7.x86_64.rpm
安装 mysql-community-libs-8.0.15-1.el7.x86_64.rpm 时如果发生如下错误
Error: Package: 2:postfix-2.10.1-9.el7.x86_64 (@anaconda)
Requires: libmysqlclient.so.18()(64bit)
Removing: 1:mariadb-libs-5.5.68-1.el7.x86_64 (@anaconda)
libmysqlclient.so.18()(64bit)
Obsoleted By: mysql-community-libs-8.0.15-1.el7.x86_64 (/mysql-community-libs-8.0.15-1.el7.x86_64)
~libmysqlclient.so.21()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
原因是缺少 Percona-XtraDB-Cluster-shared-55-5.5.37-25.10.756.el6.x86_64.rpm 这个包
wget http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster/5.5.37-25.10/RPM/rhel6/x86_64/Percona-XtraDB-Cluster-shared-55-5.5.37-25.10.756.el6.x86_64.rpm
rpm -hiv Percona-XtraDB-Cluster-shared-55-5.5.37-25.10.756.el6.x86_64.rpm
启动
systemctl start mysqld
systemctl daemon-reload
修改 root 密码
查找 root 临时密码
grep "A temporary password is generated for root@localhost" /var/log/mysqld.log
2020-11-20T06:21:53.116940Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ;RpuaqB<4czq
修改密码
mysql -uroot -p ;RpuaqB<4czq
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 12
Server version: 8.0.15
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql-password';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
为安装 wordpress 准备数据库和用户
在 mysql 命令行模式下执行如下命令
# 创建数据库
create database wordpress;
# 创建用户
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
# 授权
GRANT all privileges ON wordpress.* TO 'wpuser'@'localhost';
# 使用密码登陆
ALTER USER 'wpuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
# 刷新
FLUSH PRIVILEGES;
my.cnf 在哪里
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
字符集
从 8.0 开始,字符集默认为 utf8mb4
mysql> show variables like '%charac%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)
centos 8.2 安装 mysql 8.0.15