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

源代码 2024-9-7 20:10:08 42 0 来自 中国
安装包下载

Mysql下载地址
安装步骤

1. 添加群组:mysql

[root@ss-1 mysql]# groupadd mysql2. 添加用户: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 -y5. 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=mysql2022-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 210062022-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=+&Kn7Bya6. 开启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/mysql2022-09-13T05:57:16.897010Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended[1]+  Done                    ./bin/mysqld_safe --user=mysql8. 拷贝配置文件

$> cp support-files/mysql.server /etc/init.d/mysql.server9. 配置环境变量

export PATH=$PATH:/usr/local/mysql/bin最好写入 /etc/profile 文件
10. 启动mysql

[root@ss-1 workspace_mysql]# /etc/init.d/mysql.server startStarting MySQL.. SUCCESS! [root@ss-1 workspace_mysql]# netstat -tunlp | grep mysqltcp6       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 12Server version: 8.0.28Copyright (c) 2000, 2022, Oracle and/or its affiliates.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> 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;
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-11-21 19:36, Processed in 0.167427 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表