mysql 8.0.18安装部署和配置

安装编译环境

yum -y install numactl libaio-devel.x86_64

提前修改mysql配置文件

由于是绿色版,所以提前修改配置文件再执行后面的编译,主要是忽略表名大小写问题
修改配置文件:
vi /etc/my.cnf
修改内容如下:
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/tmp/mysql.sock
lower_case_table_names=1
#必填项
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[client]
port=3306
#这里客户端也指定和mysqld一样的路径,不然客户端登录会报错
socket=/usr/local/mysql/tmp/mysql.sock

创建mysql目录并下载

进入目录安装目录
cd /usr/local
下载安装包
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

安装流程

解压安装包
由于xz压缩是两层压缩,外层是xz,里层才说tar,所以要解压两次,xz比tar压缩文件更小,但是解压会慢一些,耐心等待...
xz -d mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar

解压的包重命名为mysql
mv  mysql-8.0.18-linux-glibc2.12-x86_64  mysql

创建数据存储目录
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/tmp
mkdir /usr/local/mysql/log

创建mysql用户和分组
groupadd mysql
useradd -r -g mysql mysql

给mysql文件夹授权
chown -R mysql:mysql /usr/local/mysql

进入mysql文件夹
cd mysql

初始化数据库,自动生成密码后记录下来,登录时需要使用此密码
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

执行结果如下图:

相关配置

开机自动启动设置
进入/usr/local/mysql/support-files进行设置
cd support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d

注册服务
chkconfig --add mysql
查看服务是否注册成功:
chkconfig --list mysql
Note: This output shows SysV services only and does not include native
       systemd services. SysV configuration data might be overridden by native
       systemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.   To see services enabled on particular target use   'systemctl list-dependencies [target]'.
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

修改配置
vi /etc/ld.so.conf
添加内容:
/usr/local/mysql/lib

配置环境变量
vim /etc/profile
添加以下内容:
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
执行生效:
source /etc/profile

启动服务
service mysql start
报错:
Starting MySQL.2019-11-14T08:48:49.437006Z mysqld_safe error: log-error set to '/usr/local/mysql/log/error.log', however file don't exists. Create writable for user 'mysql'.
问题是没有error.log文件,在对应的路径创建文件;
vi /usr/local/mysql/log/error.log
保存退出

启动服务,成功...

报错:
Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql/data/izj6c7cw39l5fyzjcjxl9uz.pid).
重新授权:
chown -R mysql:mysql /usr/local/mysql/log
chown -R mysql:mysql /usr/local/mysql/data

启动服务,成功... 

修改密码
进入mysql输入指令:
mysql -u root -p
然后输入之前保留下来的密码进入操作界面....
修改密码指令:
alter user 'root'@'localhost' identified by '123456';
密码修改成功....

修改非localhost访问权限
先进入mysql用户,必须是mysql用户:
use mysql;
查询:
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
select 'host' from user where user='root';

通过工具访问报错, 登录的加密规则 问题

解决办法:
ALTER USER 'root' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;#修改加密规则
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '用户密码';#重新更新一下密码
FLUSH PRIVILEGES; #刷新权限
问题搞定...

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注