DSS部署-6、Mysql安装

Centos7二进制文件安装MySQL5.7.25

1、删除centos系统自带的mariadb数据库防止发生冲突

rpm -qa|grep mariadb
rpm -e mariadb-libs --nodeps

2、安装libaio库
yum -y install libaio

3、下载并解压mysql-5.7.25

cd /opt/modules/
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
tar xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

4、查看是否有mysql用户和mysql用户组

cat /etc/passwd|grep mysql
cat /etc/group|grep mysql# 如果存在,则删除用户和用户组userdel -r mysql

5、创建mysql用户及其用户组

groupadd mysql
useradd -r -g mysql mysql

6、设置mysql用户为非登陆用户
usermod -s /sbin/nologin mysql

7、创建basedir、datadir目录、pid文件

mkdir /opt/mysql
mkdir /opt/mysql/data
mv mysql-5.7.25-linux-glibc2.12-x86_64/* /opt/mysql/
touch /opt/mysql/mysqld.pid
chown -R mysql:mysql /opt/mysql

8、创建日志

touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log

9、创建socket文件

touch /tmp/mysql.sock
chown mysql:mysql /tmp/mysql.sock

10、创建配置文件vim /etc/my.cnf并加入如下内容

[mysqld]
character-set-server=utf8
user=mysql
port=3306
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/opt/mysql/mysqld.pid

[client]
port=3306
socket=/tmp/mysql.sock

11、安装初始化

cd /opt/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql

成功即为如下图所示,记录临时密码。

[root@bigdata-senior01 modules]# mv mysql-5.7.25-linux-glibc2.12-x86_64/* /opt/mysql/
[root@bigdata-senior01 modules]# touch /opt/mysql/mysqld.pid
[root@bigdata-senior01 modules]# chown -R mysql:mysql /opt/mysql
[root@bigdata-senior01 modules]# touch /var/log/mysqld.log
[root@bigdata-senior01 modules]# chown mysql:mysql /var/log/mysqld.log
[root@bigdata-senior01 modules]# touch /tmp/mysql.sock
[root@bigdata-senior01 modules]# chown mysql:mysql /tmp/mysql.sock
[root@bigdata-senior01 modules]# vim /etc/my.cnf
[root@bigdata-senior01 modules]# cd /opt/mysql/bin/
[root@bigdata-senior01 bin]# ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
2022-01-05T06:30:34.747800Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-01-05T06:30:35.045935Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-01-05T06:30:35.085211Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-01-05T06:30:35.167573Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: fd58c915-6df0-11ec-96b4-000c297b38d9.
2022-01-05T06:30:35.179666Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-01-05T06:30:35.185087Z 1 [Note] A temporary password is generated for root@localhost: &:yE0ZgoexP1
[root@bigdata-senior01 bin]#

临时密码:&:yE0ZgoexP1

kvm的虚拟机密码:

Lkp>amgj>3Ys

12、设置开机启动
复制启动脚本到资源目录:
cp ../support-files/mysql.server /etc/rc.d/init.d/mysqld
增加mysqld控制脚本权限:
chmod +x /etc/rc.d/init.d/mysqld
将mysqld加入到系统服务:
chkconfig --add mysqld
检查mysqld服务是否生效:
chkconfig --list mysqld
命令输出类似如下:

[root@hadoop bin]# ll ../support-files/mysql.server
-rwxr-xr-x 1 mysql mysql 10576 Dec 21  2018 ../support-files/mysql.server
[root@hadoop bin]# cp ../support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@hadoop bin]# chmod +x /etc/rc.d/init.d/mysqld
[root@hadoop bin]# chkconfig --add mysqld
[root@hadoop bin]# chkconfig --list mysqld

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

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@hadoop bin]#

现在即可使用service命令控制mysql启动、停止。

PS:删除启动命令:
chkconfig --del mysqld

13、启动mysqld服务
service mysqld start

[root@hadoop bin]# chkconfig --del mysqld
[root@hadoop bin]# service mysqld start
Starting MySQL. SUCCESS!
[root@hadoop bin]#

14、环境变量配置
编辑/etc/profile,加入如下内容:
export PATH=$PATH:/opt/mysql/bin
执行命令使其生效:

source /etc/profile

15、登录mysql(使用随机生成的那个密码)
mysql -uroot -p'Lkp>amgj>3Ys'
修改root密码:
mysql> alter user "root"@"localhost" identified by "jereh123";
刷新权限:
mysql> flush privileges;
退出mysql,使用新密码登录mysql。

[root@hadoop bin]# vim /etc/profile
[root@hadoop bin]# source /etc/profile
[root@hadoop bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user "root"@"localhost" identified by "jereh123";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@hadoop bin]# mysql -uroot -pjereh123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


16、添加远程登录用户

默认只允许 root 帐户在本地登录mysql,如果要在其它机器上连接MySQL,必须修改 root 允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,可以添加一个新的帐户。

mysql> grant all privileges on *.* to "root"@"%" identified by "jereh123" with grant option;

17、开启防火墙mysql3306端口的外部访问

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

参数说明:

–zone:作用域,网络区域定义了网络连接的可信等级。
–add-port:添加端口与通信协议,格式:端口/通信协议,协议为tcp或udp。
–permanent:永久生效,没有此参数系统重启后端口访问失败。
18、重新启动mysql
[root@test ~]# systemctl restart mysqld.service
19、常见错误
1 mysql5.7初始化密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before
2 修改mysql密码出现报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corres
3 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this st
4 centos mysql 端口_Linux CentOS Mysql修改默认端口
5 mysql 5.7安全策略设置 报错ERROR 1193 (HY000): Unknown system variable 'validate_password
6 CentOS 7下启动、关闭、重启、查看MySQL服务
7 centos7 安装MySQL7 并更改初始化密码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沧海之巅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值