【数据库】centos 7系统,二进制方式安装mysql

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介: 【数据库】centos 7系统,二进制方式安装mysql

正文


安装包下载

Mysql下载地址


安装步骤


1. 添加群组:mysql

[root@ss-1 mysql]# groupadd mysql


2. 添加用户:mysql

[root@ss-1 mysql]# useradd -r -g mysql -s /bin/false mysql
  • -r 表示建立系统账号
  • -g 指定用户所在的群组
  • -s /bin/false 该用户不可登录


3. 解压安装包

[root@ss-1 mysql]# cd /usr/local
[root@ss-1 mysql]# tar xvf /path/to/mysql-VERSION-OS.tar.xz
[root@ss-1 mysql]# ln -s ~/workspace_mysql/mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local/mysql


4. 创建文件夹:mysql-files

[root@ss-1 mysql]# cd mysql
[root@ss-1 mysql]# mkdir mysql-files
[root@ss-1 mysql]# chown mysql:mysql mysql-files
[root@ss-1 mysql]# chmod 750 mysql-files
 yum install libaio -y


5. mysql 初始化

[root@ss-1 mysql]# ./bin/mysqld --initialize --user=mysql
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
#如果出现上面的报错,就是缺少 libaio 库,执行下面的命令安装上即可。
[root@ss-1 mysql]# yum install libaio -y
[root@ss-1 mysql]# ./bin/mysqld --initialize --user=mysql
2022-09-13T05:31:27.610325Z 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.
2022-09-13T05:31:27.610559Z 0 [System] [MY-013169] [Server] /root/workspace_mysql/mysql-8.0.28-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 21006
2022-09-13T05:31:27.633452Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-13T05:31:29.433746Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-13T05:31:31.144844Z 0 [Warning] [MY-013829] [Server] Missing data directory for ICU regular expressions: /root/workspace_mysql/mysql-8.0.28-linux-glibc2.12-x86_64/lib/private/.
2022-09-13T05:31:32.473696Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: kIg=+&Kn7Bya


6. 开启ssl


[root@ss-1 mysql]# ./bin/mysql_ssl_rsa_setup

mysql5.7之前的版本是不提供ssl安全连接的,其在网络中数据都是以明文进行传输的。mysql_ssl_rsa_setup程序用于创建 SSL 证书和密钥文件以及 RSA 密钥对文件,以支持使用 SSL 的安全连接和使用 RSA 通过未加密连接的安全密码交换(如果这些文件丢失)。 如果现有的 SSL 文件已经过期,mysql_ssl_rsa_setup也可用于创建新的 SSL 文件。


7. 后台运行 mysql_safe

[root@ss-1 mysql]# mkdir /var/log/mariadb
[root@ss-1 mysql]# touch /var/log/mariadb/mariadb.log
[root@ss-1 mysql]# chown -R mysql:mysql /var/log/mariadb
[root@ss-1 mysql]# ./bin/mysqld_safe --user=mysql &      
[1] 21262
[root@ss-1 mysql]# 2022-09-13T05:57:15.546134Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
2022-09-13T05:57:15.599043Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2022-09-13T05:57:16.897010Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
[1]+  Done                    ./bin/mysqld_safe --user=mysql


8. 拷贝配置文件

$> cp support-files/mysql.server /etc/init.d/mysql.server


9. 配置环境变量

export PATH=$PATH:/usr/local/mysql/bin

最好写入 /etc/profile 文件


10. 启动mysql

[root@ss-1 workspace_mysql]# /etc/init.d/mysql.server start
Starting MySQL.. SUCCESS! 
[root@ss-1 workspace_mysql]# netstat -tunlp | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      22386/mysqld        
tcp6       0      0 :::33060                :::*                    LISTEN      22386/mysqld


11. 验证连接

[root@ss-1 tmp]# mysql -h 127.0.0.1 -u root -p          
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.28
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> 
mysql>

可以看到,数据库连接已经没问题了。


三、修改 root 密码


虽然 mysql 数据库已经能连接了,但还没结束,当我们执行 show databases; 时,会提示如下错误:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

意思是提醒咱们不要用初始密码,这是需要修改密码:

mysql> alter user user() identified by '123456';
Query OK, 0 rows affected (0.03 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
mysql>

修改完密码之后,可以看到错误就消失了。


四、创建 'root'@'%' 用户


初始 root@localhost 用户是无法远程登录的,要远程登录,咱们还需要创建 root@%用户。

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


1.webp.jpg



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
8天前
|
关系型数据库 MySQL Linux
通过虚拟机进行安装Centos7.0并且安装MySQL
通过虚拟机进行安装Centos7.0并且安装MySQL
27 0
|
1天前
|
安全 关系型数据库 MySQL
CentOS 8 中安装与配置 MySQL
CentOS 8 中安装与配置 MySQL
12 3
|
1天前
|
SQL 运维 关系型数据库
|
2天前
|
关系型数据库 MySQL 数据安全/隐私保护
mysql8.0.26忘记密码后重置(centos8)
mysql8.0.26忘记密码后重置(centos8)
12 2
|
2天前
|
安全 关系型数据库 MySQL
Centos、OpenEuler系统安装mysql
Centos、OpenEuler系统安装mysql
10 1
|
10天前
|
关系型数据库 MySQL Linux
蓝易云 - CentOS7用二进制安装MySQL5.7
以上步骤即可完成在CentOS 7上通过二进制包安装MySQL 5.7。
22 2
|
3天前
|
关系型数据库 MySQL Linux
MySQL8.0安装(Linux - centos)
MySQL8.0安装(Linux - centos)
13 0
|
7天前
|
关系型数据库 MySQL Linux
Linux centos 6.5 - Mysql 安装 、卸载、修改密码、忘记密码 并异常处理
Linux centos 6.5 - Mysql 安装 、卸载、修改密码、忘记密码 并异常处理
13 0
|
8天前
|
存储 关系型数据库 MySQL
CentOS上安装MySQL 8.0的详细教程
CentOS上安装MySQL 8.0的详细教程
|
1天前
|
存储 关系型数据库 MySQL

热门文章

最新文章