Tommonkey

All greatness comes from a brave beginning

0%

mymysql安装8.x.x版本

Mysql安装包选择与下载

这里选择的是:mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz 安装包方式安装(也采用rpm的方式安装),各位根据自己的系统和架构选择合适安装包下载,通过uname -a查看即可系统信息。下载地址如下:

https://dev.mysql.com/downloads/mysql/
download

部署配置

假定系统是全新的环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
   tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
# 移动到/usr/local/ 目录下并重命名为mysql
mv ./mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz /usr/local/mysql
# 使用 cd 命令进入 /usr/local/ 目录下,创建用户与用户组并授权
cd /usr/local/
groupadd mysql
useradd -r -g mysql mysql
cd mysql # 进入mysql文件夹下进行授权
chown -R mysql:mysql ./
# 在mysql文件夹下创建data目录
mkdir data
# 初始化数据库并注意生成的随机密码
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 修改当前用户
chown -R root:root ./
chown -R mysql:mysql data

2

1
2
3
4
5
# 在当前mysql文件夹下创建文件
touch my-default.cnf
chmod 777 ./my-default.cnf
# 复制当前文件夹下的文件到/etc/my.cnf
cp ./my-default.cnf /etc/my.cnf

配置my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[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 = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 3306
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# 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

开机自启

进入/usr/local/mysql/support-files进行设置

1
2
3
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql

注册服务

1
2
   chkconfig --add mysql
chkconfig --list mysql # 查看是否成功

配置路径与环境变量

1
2
3
4
5
6
7
8
9
vim /etc/ld.so.conf
# 添加如下内容并保存退出
/usr/local/mysql/lib

# 配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
# 保存退出
source /etc/profile

3

修改密码

登录mysql并修改初始随机密码

mysql -u root -p
alter user ‘root‘@’localhost’ identified by ‘12345’;
flush privileges;

报错解决

出现如下报错:

Can ‘t connect to local MySQL server through socket ‘/tmp/mysql.sock
解决办法:重启服务
systemctl restart mysql

over!!!

奖励作者买杯可乐?