- 进入安装目录
/usr/local
- 下载
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 解压,重命名
tar -Jxvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xzmv mysql-8.0.20-linux-glibc2.12-x86_64 mysql8
- 创建用户组、用户
# 需要进入 /usr/local
#创建用户组:groupadd
#创建用户:useradd(-r 创建系统用户,-g 指定用户组)groupadd mysql
useradd -r -g mysql mysql
- 数据目录
# 创建数据目录
mkdir -p /data/mysql# 授权
mkdir -p /data/mysql #创建目录
chown mysql:mysql -R /data/mysql #赋予权限
- MySQL初始化文件
# 在 /etc/ 下创建 my.cnf 配置文件用于初始化 MySQL 数据库
vim /etc/my.cnf
my.cnf文件内容
# 编辑配置文件内容如下
[mysql]
default-character-set=utf8mb4
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /tmp/mysql.sockbasedir = /usr/local/mysql
datadir = /data/mysqllog-bin = /data/mysql/mysql-bin
innodb_data_home_dir =/data/mysql
innodb_log_group_home_dir =/data/mysql
log-error =/data/mysql/mysqlError.log
pid-file =/data/mysql/mysql.pid
character-set-server=utf8mb4
lower_case_table_names=1
autocommit =1
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
#query_cache_size = 128M
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
binlog_format=mixed
binlog_expire_logs_seconds =864000
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
注意:配置文件中涉及到的文件需要提前创建好并授权,否则初始化会报错
- 初始化数据库
初始化命令:注意文件夹名称。
–defaults-file:指定配置文件(要放在–initialize 前面)
–user: 指定用户
–basedir:指定安装目录
–datadir:指定初始化数据目录
–intialize-insecure:初始化无密码(否则生成随机密码)
进入/usr/local/mysql8/bin目录下执行:
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
问题1
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum install -y libaio
- 查看密码
my.cnf配置中log-error =/data/mysql/mysqlError.log
vim /data/mysql/mysqlError.log
- 将mysql.server放置到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- 启动
service mysql startps -ef|grep mysql
11. 修改密码
#bin目录下,初始密码在查看 my.cnf配置中log-error =/data/mysql/mysqlError.log
./mysql -u root -p
执行以下代码修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
- 配置远程连接
use mysql;
update user set host='%' where user='root';
flush privileges;
13. 查看安装路径及安装环境
whereis mysql;
whereis mysqldump;
文件缺失,手动配置
vi /etc/profile
最后一行添加
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
再次检查
whereis mysql;
whereis mysqldump;