暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

centos8部署mysql8.0.20数据库

原创 NIU 恩墨学院 2023-02-03
340

操作系统为centos8


#禁用防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

节点执行:
#禁用networkmanager
systemctl stop NetworkManager
systemctl disable NetworkManager

节点执行:
#禁用selinux
vi /etc/selinux/config

节点执行:
#禁用ntp
systemctl stop ntpd
systemctl disable ntpd
mv /etc/ntp.conf /etc/ntp.conf.old

创建指定路径:

创建mysql用户
groupadd mysql
useradd -r -g mysql mysql
passwd 123456

创建目录
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/log
mkdir -p /usr/local/mysql/relaylog
chown -R mysql:mysql /usr/local/mysql/relaylog/
chmod -R 775 /usr/local/mysql

所有节点执行:
授权mysql
chown -R mysql:mysql /usr/local/mysql/data/
chown -R mysql:mysql /usr/local/mysql/

节点执行:
上传mysql安装到服务器文件系统

所有节点执行:
解压文件
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
重命名:
mv /soft/mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql


配置mysql参数文件:

--参数文件:
[root@localhost data]# more /etc/my.cnf
[client]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysqld.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names = 1

#relay log
relay_log = /usr/local/mysql/relaylog/relay.log
relay-log-index = /usr/local/mysql/relaylog/relay.index
master_info_repository = table
relay_log_info_repository = table
relay_log_purge = 0
read_only = 0

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

初始化:

/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --lower-case-table-names=1 --datadir=/usr/local/mysql/data/ --user=mysql

日志会生成初次登录mysql的密码,需要强制修改密码,否则无法操作数据库

初始化日志:
/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --lower-case-table-names=1 --datadir=/usr/local/mysql/data/ --user=mysql
2023-02-02T05:08:12.575829Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-02-02T05:08:12.575923Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 98569
2023-02-02T05:08:12.584855Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-02T05:08:13.096433Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-02T05:08:14.277257Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dMhMfe<wk9k_
[root@localhost data]# /usr/local/mysql/support-files/mysql.server restart
Shutting down MySQL. SUCCESS!
Starting MySQL.Logging to '/usr/local/mysql/data/err.log'.
SUCCESS!


!!!!!!!!!!!!重新初始化,需要把data下的文件清除,否则不能重新初始化。!!!!!!!!


启动数据库服务:
--软连接
ln -s /usr/local/mysql/support-files/mysql.server /usr/bin/mysqld

启动:mysqld start;

关闭:mysqld stop;


登录mysql:
--软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

登录

mysql -uroot -p

修改密码:

alter user'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;



设置mysql服务开启自启:

1.--检查自启列表
chkconfig --list

2.--我们设置开机启动需要将mysql.server 文件复制到 /etc/rc.d/init.d/ 目录下mysql 文件 我们的mysql.server 文件一般都在安装的根目录下的 support-files 目录下
cp /usr/local/mysql/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql

3.--赋权
chmod +x /etc/init.d/mysql

4.--添加服务
chkconfig -add mysql

5.--查看服务列表
chkconfig --list

[root@localhost /]# chkconfig --list

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]'.

[root@localhost /]# cp /usr/local/mysql/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
cp: cannot stat '/usr/local/mysql/mysql/support-files/mysql.server': No such file or directory
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
[root@localhost /]# chmod +x /etc/init.d/mysql
[root@localhost /]# chkconfig --add mysql
[root@localhost /]# chkconfig --list

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



本地登录:

--赋权操作5.X
grant all privileges on *.* to 'root'@'%' identified by '123456';

grant all privileges on *.* to 'root'@'%' identified by '123456';

grant all privileges on root.* to test@'localhost';

create user test@'localhost' identified by '123456';

grant all privileges on test.* to test@'localhost';

grant all privileges on test.'%' to test@'localhost';

grant all privileges on *.* to 'root'@'%' ;

grant all privileges on *.* to 'test'@'%' ;

--赋权操作 mysql8.0
select host,user from mysql.user;

update user set host='%' where user='test' ;

GRANT ALL ON *.* TO 'test'@'%';

grant all privileges on *.* to 'test'@'%' ;

flush privileges;


ALTER USER 'root'@'%' IDENTIFIED BY '你的mysql密码' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #修改密码
FLUSH PRIVILEGES; #刷新数据

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #修改密码
FLUSH PRIVILEGES; #刷新数据

mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论