• linux环境搭建mysql5.7总结


    以下安装方式,在阿里云与腾讯云服务器上都测试可用。
    一、进入到opt目录下,执行:

    [root@master opt]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    

    解压:

    [root@master opt]# tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
    

    修改名字:

    [root@master opt]# mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql-5.7.26
    

    移动到/usr/local

    [root@master opt]# mv mysql-5.7.26 /usr/local/
    

    创建mysql用户组和用户:

    1. [root@master opt]# groupadd mysql
    2. [root@master opt]# useradd -r -g mysql mysql

    进入/usr/local/mysql-5.7.26/目录下,创建一个/data/mysql目录

    1. [root@master opt]# cd /usr/local/mysql-5.7.26/
    2. [root@master opt]# mkdir data
    3. [root@master opt]# cd data/
    4. [root@master opt]# mkdir mysql

    对该目录进行授权设置:

    [root@master opt]# chown mysql:mysql -R ../data/mysql/
    

    设置vim /etc/my.cnf参数

    1. [mysqld]
    2. bind-address=xxx.xxx.xxx.xxx
    3. port=3306
    4. user=mysql
    5. basedir=/usr/local/mysql-5.7.26
    6. datadir=/usr/local/mysql-5.7.26/data/mysql
    7. socket=/tmp/mysql.sock
    8. log-error=/usr/local/mysql-5.7.26/data/mysql/mysql.err
    9. pid-file=/usr/local/mysql-5.7.26/data/mysql/mysql.pid
    10. #character config
    11. character_set_server=utf8
    12. symbolic-links=0
    13. [client]
    14. socket=/tmp/mysql.sock

    初始化mysql:

    进入到/usr/local/mysql-5.7.26/bin目录,执行

    [root@master opt]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-5.7.26/ --datadir=/usr/local/mysql-5.7.26/data/mysql/ --user=mysql --initialize
    

    获取初始化生成的密码:zuN4F%E)R!q3

    1. [root@master bin]# cat /usr/local/mysql-5.7.26/data/mysql/mysql.err
    2. 2021-10-20T08:09:00.331096Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    3. 2021-10-20T08:09:01.371244Z 0 [Warning] InnoDB: New log files created, LSN=45790
    4. 2021-10-20T08:09:01.495582Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    5. 2021-10-20T08:09:01.557026Z 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: fc058b1f-317c-11ec-adb1-00163e061e0a.
    6. 2021-10-20T08:09:01.558519Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    7. 2021-10-20T08:09:01.558927Z 1 [Note] A temporary password is generated for root@localhost: zuN4F%E)R!q3

    先进入/usr/local/mysql-5.7.26/support-files目录,看到有mysql.server脚本——

    1. [root@master mysql-5.7.26]# pwd
    2. /usr/local/mysql-5.7.26
    3. [root@master mysql-5.7.26]# ll
    4. total 56
    5. drwxr-xr-x 2 root root 4096 Oct 20 15:59 bin
    6. -rw-r--r-- 1 7161 31415 17987 Apr 13 2019 COPYING
    7. drwxr-xr-x 3 root root 4096 Oct 20 15:29 data
    8. drwxr-xr-x 2 root root 4096 Oct 20 15:27 docs
    9. drwxr-xr-x 3 root root 4096 Oct 20 15:27 include
    10. drwxr-xr-x 5 root root 4096 Oct 20 15:27 lib
    11. drwxr-xr-x 4 root root 4096 Oct 20 15:27 man
    12. -rw-r--r-- 1 7161 31415 2478 Apr 13 2019 README
    13. drwxr-xr-x 28 root root 4096 Oct 20 15:27 share
    14. drwxr-xr-x 2 root root 4096 Oct 20 15:27 support-files
    15. [root@master mysql-5.7.26]# cd support-files/
    16. [root@master support-files]# ll
    17. total 24
    18. -rw-r--r-- 1 7161 31415 773 Apr 13 2019 magic
    19. -rwxr-xr-x 1 7161 31415 1061 Apr 13 2019 mysqld_multi.server
    20. -rwxr-xr-x 1 7161 31415 894 Apr 13 2019 mysql-log-rotate
    21. -rwxr-xr-x 1 7161 31415 10576 Apr 13 2019 mysql.server

    启动执行:

    1. [root@master support-files]# ./mysql.server start
    2. Starting MySQL. [ OK ]

    然后切换到/usr/local/mysql-5.7.26/bin目录,执行进入mysql的指令:

    [root@master bin]# ./mysql -u root -p
    

    最后,就是修改密码操作了:

    1. mysql> SET PASSWORD = PASSWORD('xxx');
    2. Query OK, 0 rows affected, 1 warning (0.00 sec)
    3. mysql> ALTER USER 'xxx'@'localhost' PASSWORD EXPIRE NEVER;
    4. Query OK, 0 rows affected (0.00 sec)
    5. mysql> flush privileges;
    6. Query OK, 0 rows affected (0.00 sec)

    设置远程访问:

    1. mysql> grant all on *.* to xxx@'%' identified by 'xxx' with grant option;
    2. Query OK, 0 rows affected, 1 warning (0.00 sec)
    3. mysql> flush privileges;
    4. Query OK, 0 rows affected (0.00 sec)

    设置开机启动:

    先将/usr/local/mysql-5.7.26/support-files/ 文件夹下的mysql.server文件复制到 /etc/rc.d/init.d/ 目录下

    1. [root@master init.d]# cp /usr/local/mysql-5.7.26/support-files/mysql.server /etc/rc.d/init.d/
    2. [root@master init.d]# ll
    3. total 40
    4. -rwxr-xr-x 1 root root 2415 Jun 30 21:19 aegis
    5. -rw-r--r--. 1 root root 18434 Jul 24 2020 functions
    6. lrwxrwxrwx 1 root root 35 Aug 10 11:14 jexec -> /usr/java/latest/.java/init.d/jexec
    7. -rwxr-xr-x 1 root root 10576 Oct 20 16:23 mysql.server
    8. -rw-r--r--. 1 root root 1161 Mar 23 2021 README

    将mysql.server修改为mysqld

    [root@master init.d]# mv mysql.server mysqld
    

    添加为服务: chkconfig --add mysqld

    查看服务列表: chkconfig --list

    1. [root@master init.d]# chkconfig --list
    2. Note: This output shows SysV services only and does not include native
    3. systemd services. SysV configuration data might be overridden by native
    4. systemd configuration.
    5. If you want to list systemd services use 'systemctl list-unit-files'.
    6. To see services enabled on particular target use
    7. 'systemctl list-dependencies [target]'.
    8. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
    9. jexec 0:off 1:on 2:on 3:on 4:on 5:on 6:off
    10. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    3、4、5状态为 on 则表示设置开机启动成功。

  • 相关阅读:
    通用HttpClient封装
    学习笔记-.net安全之XmlSerializer反序列化
    【Try to Hack】php命令执行和代码执行
    【数据结构与算法】泛型的介绍及使用
    力扣--第三大的数
    能碳双控| AIRIOT智慧能碳管理解决方案
    【MySQL日志与备份篇】其他数据库日志
    一点一点学习C++之笔记004
    构建高效的广告投放系统:应用架构的设计与实现
    接口自动化测试数据驱动DDT模块使用
  • 原文地址:https://blog.csdn.net/weixin_40706420/article/details/134522901