java中的接口是类吗
230
2022-11-06
【CentOS】安装配置 MySQL
文章目录
1、卸载 Linux 系统自带的 MariaDB2、解压 MySQL 数据库安装包3、安装 MySQL 数据库4、修改 MySQL 数据库配置5、启动 MySQL 服务6、查询 MySQL 数据库默认密码7、MySQL 数据库初始化8、root 用户本地远程访问授权
准备环境集群(一主两从即可)集群可以联网MySQL 数据库安装包:mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar 提取码:e0yb
1、卸载 Linux 系统自带的 MariaDB
首先查看 Linux 系统中 MariaDB 的安装情况:
[root@server ~]# rpm -qa | grep mariadbmariadb-libs-5.5.56-2.el7.x86_64
以上结果显示 Linux 系统中已经按照了 mariadb-libs-5.5.56-2.el7.x86_64 软件包, 需要将其卸载:
# 卸载 mariadb 软件包[root@server ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64[root@server ~]# rpm -qa | grep mariadb[root@server ~]#
返回顶部
2、解压 MySQL 数据库安装包
通过 XShell 将安装包传输到 /download 目录下:
对 MySQL 安装包进行解压:
# 新建 mysql-5.7.22文件夹存放mysql的安装包[root@server download]# mkdir mysql-5.7.22# 查看[root@server download]# ll总用量 970980-rw-r--r--. 1 root root 210606807 2月 19 13:18 hadoop-2.7.1.tar.gz-rw-r--r--. 1 root root 185646832 12月 24 17:31 jdk-8u181-linux-x64.tar.gzdrwxr-xr-x. 2 root root 6 2月 24 20:52 mysql-5.7.22-rw-r--r--. 1 root root 598026240 2月 24 16:13 mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar# 解压[root@server download]# tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar -C /../download/mysql-5.7.22mysql-community-libs-5.7.22-1.el7.x86_64.rpmmysql-community-libs-compat-5.7.22-1.el7.x86_64.rpmmysql-community-embedded-5.7.22-1.el7.x86_64.rpmmysql-community-test-5.7.22-1.el7.x86_64.rpmmysql-community-server-5.7.22-1.el7.x86_64.rpmmysql-community-client-5.7.22-1.el7.x86_64.rpmmysql-community-server-minimal-5.7.22-1.el7.x86_64.rpmmysql-community-devel-5.7.22-1.el7.x86_64.rpmmysql-community-common-5.7.22-1.el7.x86_64.rpmmysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpmmysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpmmysql-community-embedded-compat-5.7.22-1.el7.x86_64.rpm
返回顶部
3、安装 MySQL 数据库
按如下顺序依次按照 MySQL 数据库的 mysql common、mysql libs、mysql client 软件包:
[root@server mysql-5.7.22]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm 警告:mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中... ################################# [100%]正在升级/安装... 1:mysql-community-common-5.7.22-1.e################################# [100%][root@server mysql-5.7.22]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm 警告:mysql-community-libs-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中... ################################# [100%]正在升级/安装... 1:mysql-community-libs-5.7.22-1.el7################################# [100%][root@server mysql-5.7.22]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm 警告:mysql-community-client-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中... ################################# [100%]正在升级/安装... 1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@server mysql-5.7.22]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 警告:mysql-community-server-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中... ################################# [100%]正在升级/安装... 1:mysql-community-server-5.7.22-1.e################################# [100%]
返回顶部
4、修改 MySQL 数据库配置
在 /etc/my.cnf 文件中添加如表所示的 MySQL 数据库配置项:
# 将以下配置信息添加到/etc/my.cnf 文件 symbolic-links=0 配置信息的下方。default-storage-engine=innodbinnodb_file_per_tablecollation-server=utf8_general_ciinit-connect='SET NAMES utf8'character-set-server=utf8
返回顶部
5、启动 MySQL 服务
[root@server mysql-5.7.22]# systemctl start mysqld # 启动数据库服务[root@server mysql-5.7.22]# systemctl status mysqld # 查看状态● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2022-02-24 21:34:42 CST; 14s ago Docs: man:mysqld(8) Process: 2070 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 1996 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 2072 (mysqld) CGroup: /system.slice/mysqld.service └─2072 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid2月 24 21:34:38 server systemd[1]: Starting MySQL Server...2月 24 21:34:42 server systemd[1]: Started MySQL Server.
mysqld 进程状态为 active (running),则表示 MySQL 数据库正常运行;如果 mysqld 进程状态为 failed,则表示 MySQL 数据库启动异常,此时需要排查 /etc/my.cnf 文件。
返回顶部
6、查询 MySQL 数据库默认密码
MySQL 数据库安装后的默认密码保存在 /var/log/mysqld.log 文件中,在该文件中以 password 关键字搜索默认密码:
[root@server mysql-5.7.22]# cat /var/log/mysqld.log | grep password2022-02-24T13:34:38.739331Z 1 [Note] A temporary password is generated for root@localhost: 2rugn,gzxuFv
MySQL 数据库是安装后随机生成的,所以每次安装后生成的默认密码不相同,这里为:2rugn,gzxuFv。
返回顶部
7、MySQL 数据库初始化
执行 mysql_secure_installation 命令初始化 MySQL 数据库,初始化过程中需要设定数据库 root 用户登录密码,密码需符合安全规则,包括大小写字符、数字和特殊符号,可设定密码为 Password123456$ 。
[root@master ~]# mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: # 输入/var/log/mysqld.log 文件中查询到的默认 root 用户登录密码The 'validate_password' plugin is installed on the server.The subsequent steps will run with the existing configurationof the plugin.Using existing password for root.Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : yNew password: # 输入新密码 Password123$Re-enter new password: # 再次输入新密码 Password123$Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y # 输入 yBy default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only for testing, and to make the installation go a bit smoother.You should remove them before moving into a production environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 输入 ySuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n # 输入 n... skipping.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 输入 y- Dropping test database...Success.- Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changes made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 输入 ySuccess.All done!
返回顶部
8、root 用户本地远程访问授权
在进行授权之前为了方便以后的使用我们先修改一下密码,mysql5.7.x 安装以后,想修改随机生成的密码为简单容易记忆的密码,如 root、123456等,这时候通过修改密码的几种方式都不行,出现密码不符合当前安全策略要求:
mysql> show variables like 'validate_password%';+--------------------------------------+--------+| Variable_name | Value |+--------------------------------------+--------+| validate_password_check_user_name | OFF || validate_password_dictionary_file | || validate_password_length | 8 || validate_password_mixed_case_count | 1 || validate_password_number_count | 1 || validate_password_policy | MEDIUM || validate_password_special_char_count | 1 |+--------------------------------------+--------+7 rows in set (0.13 sec)
密码长度要求8位,验证策略是 MEDIUM,就是长度,数字,大小写,特殊字符都得验证,因此出现如此所示的错误,就很正常了。我们可以修改validate_password_policy=0,这样就是只检查长度。另外我们觉着8位太长了,我们可以改为4:
mysql> set global validate_password_policy=0;Query OK, 0 rows affected (0.00 sec)mysql> set global validate_password_length=4;Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'validate_password%';+--------------------------------------+-------+| Variable_name | Value |+--------------------------------------+-------+| validate_password_check_user_name | OFF || validate_password_dictionary_file | || validate_password_length | 4 || validate_password_mixed_case_count | 1 || validate_password_number_count | 1 || validate_password_policy | LOW || validate_password_special_char_count | 1 |+--------------------------------------+-------+7 rows in set (0.01 sec)
接着我们进行密码的修改:
mysql> set password=password('123456');Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> exitBye[root@server mysql-5.7.22]# mysql -uroot -p123456mysql: [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 8Server version: 5.7.22 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
添加 root 用户本地访问授权:
mysql> grant all privileges on *.* to root@'localhost' identified by '123456';Query OK, 0 rows affected, 1 warning (0.00 sec)
添加 root 用户远程访问授权:
mysql> grant all privileges on *.* to root@'%' identified by '123456';Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新授权并查看 root 用户授权情况:
mysql> select user,host from mysql.user where user='root';+------+-----------+| user | host |+------+-----------+| root | % || root | localhost |+------+-----------+2 rows in set (0.00 sec)
另一种解压 mysql 安装包直接安装的方式参见我 的 partner 的博文【Hive】Hive的安装
返回顶部
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~