目录
1.下载 mysql 安装包
2.上传并解压 mysql
3.修改 mysql 文件夹名
4.创建mysql 用户和用户组
5.数据目录
(1)创建目录
(2)赋予权限
6.初始化mysql
(1)配置参数
(2)配置环境变量
(3)初始化
7.启动 MySQL
(1)启动 mysql
(2)查看 MySQL 是否启动成功
8.登录 MySQL
(1)无密码方式登录
(2)修改密码
(3)设置允许远程登录
9.设置 mysql开机自启动
(1)在/etc/rc.d/init.d/编辑一个新文件autostartmysql.sh
(2)为autostartmysql.sh赋予权限
(3) 将autostartmysql.sh添加到 chkconfig 中
(4)检查是否开机自启动
网盘资源如下
链接:https://pan.baidu.com/s/1qpChiXVAGZkrDFwlxsWMcg?pwd=f4wm 提取码: f4wm
这里的上传和解压的文件夹位置不必和我这一样,但是如果不一样要注意修改下面步骤中的路径
上传至 Linux 的/opt文件夹
解压到/usr/local文件夹下
使用命令
tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C /usr/local
.tar.gz后缀:tar -zxvf 文件名
.tar.xz后缀:tar -Jxvf 文件名
mv mysql-8.0.30-linux-glibc2.12-x86_64 mysql
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /usr/local/mysql8/datas
# 更改属主和数组
chown -R mysql:mysql /usr/local/mysql8/datas
# 更改模式
chmod -R 750 /usr/local/mysql8/datas
在/usr/local/mysql8/
下,创建my.cnf
配置文件,用于初始化MySQL数据库
[mysql]
# 默认字符集
default-character-set=utf8mb4
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /tmp/mysql.sock
# 安装目录
basedir = /usr/local/mysql8
# 数据存放目录
datadir = /usr/local/mysql8/datas/mysql
log-bin = /usr/local/mysql8/datas/mysql/mysql-bin
innodb_data_home_dir =/usr/local/mysql8/datas/mysql
innodb_log_group_home_dir =/usr/local/mysql8/datas/mysql
#日志及进程数据的存放目录
log-error =/usr/local/mysql8/datas/mysql/mysql.log
pid-file =/usr/local/mysql8/datas/mysql/mysql.pid
# 服务端使用的字符集默认为8比特编码
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
vim /etc/profile 或
vi /etc/profile
在末尾添加
export PATH=$PATH:/usr/local/mysql8/bin
更新配置
source /etc/profile
mysqld --defaults-file=/usr/local/mysql8/my.cnf --basedir=/usr/local/mysql8/ --datadir=/usr/local/mysql8/datas/mysql --user=mysql --initialize-insecure
参数:
defaults-file
:指定配置文件(要放在–initialize 前面)user
: 指定用户basedir
:指定安装目录datadir
:指定初始化数据目录intialize-insecure
:初始化无密码mysqld_safe --defaults-file=/usr/local/mysql8/my.cnf &
ps -ef|grep mysql
出现下列信息则启动成功
mysql -u root --skip-password
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
# 刷新权限
FLUSH PRIVILEGES;
mysql> use mysql
mysql> update user set user.Host='%'where user.User='root';
mysql> flush privileges;
mysql> quit
cd /etc/rc.d/init.d/
vim ./autostartmysql.sh
autostartmysql.sh内容:
#!/bin/sh
# chkconfig: 2345 10 90
# description: myservice...
/usr/local/mysql8/bin/mysqld_safe --defaults-file=/usr/local/mysql8/my.cnf &
chmod +x ./autostartmysql.sh
chkconfig --add ./autostartmysql.sh
chkconfig autostartmysql.sh on
查看是否添加成功
chkconfig --list
我们创建的新文件已经添加成功
reboot 或 shutdown -r now 立即重启
重启后
ps -ef|grep mysql
查看 mysql 是否自启动