rocky9 安装mysql

基于二进制方式

系统信息:

$ cat /etc/system-release
Rocky Linux release 9.0 (Blue Onyx)
  1. 准备安装包:

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

  1. 解压
$ tar zxvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
  1. 创建用户授权
$ useradd mysql
$ mv /usr/local/mysql-5.7.38-linux-glibc2.12-x86_64 /usr/local/mysql
$ chown mysql:mysql -R /usr/local/mysql
$ echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.bash_profile
$ source ~/.bash_profile
  1. 创建配置文件
$ tee /etc/my.cnf <
  1. 创建所需目录
$ mkdir -p /var/run/mysqld
$ chown mysql:mysql /var/run/mysqld
$ touch /var/log/mysqld.log /var/log/slow-query.log
$ chown mysql:mysql /var/log/mysqld.log
$ chown mysql:mysql /var/log/slow-query.log
  1. 创建service
$ tee /usr/lib/systemd/system/mysqld.service <
  1. 初始化数据
$ /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql
  1. 启动mysql
$ systemctl enable --now mysqld
  1. 查看状态
$ systemctl status mysqld
● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-08-17 10:47:31 CST; 11s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 13894 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
   Main PID: 13896 (mysqld)
      Tasks: 30 (limit: 23408)
     Memory: 400.3M
        CPU: 307ms
     CGroup: /system.slice/mysqld.service
             └─13896 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

8月 17 10:47:31 localhost.localdomain systemd[1]: Starting MySQL Server...
8月 17 10:47:31 localhost.localdomain systemd[1]: Started MySQL Server.
  1. 建立动态库链接
$ ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
$ ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
  1. 初始化root口令测试
$ systemctl stop mysqld
$ mysqld_safe --skip-grant-tables &
$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38-log MySQL Community Server (GPL)

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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string = password("Mysql@d523") WHERE user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

你可能感兴趣的:(rocky9 安装mysql)