• centos安装mysql8.0.20、tar包安装方式


    基础环境centos7.5,mysql版本8.0.20,通过tar包安装,安装路径/usr/local。

    mysql官网:https://dev.mysql.com/downloads/mysql/

    wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
    

    卸载centos7中自带的mariadb

    1. [root@localhost ~]# rpm -qa|grep mariadb
    2. mariadb-libs-5.5.56-2.el7.x86_64
    3. [root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

    上传并解压安装包mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz。注意压缩包是.tar.xz格式的,需要先解压、再解包。

    1. [root@CentOS7-1 tools]# xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
    2. [root@CentOS7-1 tools]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar -C /usr/local/

    在安装包下创建数据文件路径data

    1. [root@CentOS7-1 tools]# cd /usr/local/
    2. [root@CentOS7-1 local]# mv mysql-8.0.20-linux-glibc2.12-x86_64/ mysql
    3. [mysql@CentOS7-1 local]$ cd mysql
    4. [mysql@CentOS7-1 mysql]$ mkdir data

    创建mysql用户

    1. [root@CentOS7-1 mysql]# useradd mysql
    2. [root@CentOS7-1 mysql]# passwd mysql

    重命名解压后的安装包目录,并修改目录的属主属组,

    1. [root@localhost mysql]# cd ..
    2. [root@localhost local]# chown -R mysql.mysql mysql
    3. [root@localhost local]# ll
    4. 总用量 0
    5. drwxr-xr-x. 2 root root 6 4月 11 2018 bin
    6. drwxr-xr-x. 2 root root 6 4月 11 2018 etc
    7. drwxr-xr-x. 2 root root 6 4月 11 2018 games
    8. drwxr-xr-x. 2 root root 6 4月 11 2018 include
    9. drwxr-xr-x. 2 root root 6 4月 11 2018 lib
    10. drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
    11. drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
    12. drwxr-xr-x 10 mysql mysql 141 12月 8 14:12 mysql
    13. drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
    14. drwxr-xr-x. 5 root root 49 12月 13 2020 share
    15. drwxr-xr-x. 2 root root 6 4月 11 2018 src

    编辑配置文件/etc/my.cnf

    1. [root@localhost local]# cat /etc/my.cnf
    2. [mysqld]
    3. port=3306 #3306端口
    4. basedir=/usr/local/mysql # mysql的安装目录
    5. datadir=/usr/local/mysql/data # mysql数据库的数据的存放目录
    6. max_connections=10000 # 允许最大连接数
    7. max_connect_errors=10 # 允许连接失败的次数,防止有人从该主机试图攻击数据库系统
    8. character-set-server=utf8 # 服务端使用的字符集
    9. default-storage-engine=INNODB # 默认存储引擎
    10. [mysql]
    11. default-character-set=utf8 # 设置mysql客户端默认字符集

    到bin目录下初始化数据库,记录初始密码

    1. [mysql@CentOS7-1 local]$ cd mysql/bin
    2. [mysql@CentOS7-1 bin]$ ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
    3. 2021-12-07T16:29:25.936536Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
    4. 2021-12-07T16:29:25.936549Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
    5. 2021-12-07T16:29:25.937104Z 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.
    6. 2021-12-07T16:29:25.937260Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 111611
    7. 2021-12-07T16:29:25.954467Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    8. 2021-12-07T16:29:27.128120Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    9. 2021-12-07T16:29:28.520117Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: I<-VCdcL2kZb

     将mysql添加到服务

    1. [root@CentOS7-1 bin]# cd ../support-files/
    2. [root@CentOS7-1 support-files]# cp -a mysql.server /etc/init.d/mysqld
    3. [root@CentOS7-1 support-files]# chmod +x /etc/init.d/mysqld
    4. [root@CentOS7-1 support-files]# chkconfig --add mysqld

    配置环境变量/etc/profile

    1. [root@localhost bin]# echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
    2. [root@localhost bin]# source /etc/profile

    启动mysql

    1. [root@localhost bin]# service mysqld start
    2. Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
    3. .... SUCCESS!
    4. [root@localhost bin]# service mysqld status
    5. SUCCESS! MySQL running (70760)

    登录mysql

    (如遇到下面问题请参考底部问题一方法解决)

    1. [root@ecs-656621649-001 /usr/local/mysql/support-files]# mysql -uroot -p
    2. mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    1. [root@localhost bin]# mysql -uroot -p
    2. Enter password: 输入初始化时生成的密码
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 8
    5. Server version: 8.0.20
    6. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. mysql>

     修改root用户密码即相关权限。

    1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Cslc@pass123';
    2. Query OK, 0 rows affected (0.00 sec)
    3. mysql> update user set host='%' where user = 'root'; ---设置root用户可在任意主机登录,即可远程登录
    4. Query OK, 1 row affected (0.03 sec)
    5. Rows matched: 1 Changed: 1 Warnings: 0
    6. mysql> flush privileges; ---刷新权限
    7. Query OK, 0 rows affected (0.00 sec)
    8. mysql> grant all privileges on *.* to 'root'@'%';
    9. Query OK, 0 rows affected (0.02 sec)
    10. mysql> flush privileges;
    11. Query OK, 0 rows affected (0.01 sec)
    问题一解决办法:

    根据报错内容可以看出,是因为在启动mysql的时候加载了libtinfo.so.5库文件。此时我们可以查看redhat9系统中是否存在改库文件。

    1. [root@server bin]# find / -name 'libncurses*'
    2. /usr/lib64/libncurses.so.6
    3. /usr/lib64/libncursesw.so.6
    4. /usr/lib64/libncurses.so.6.2
    5. /usr/lib64/libncursesw.so.6.2

    从上面的查询结果中可以看到,我现在使用的系统中并没有安装对应5版本的库文件,这个时候可以将高版本创建软连接到5版本。

    [root@server bin]# ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
    

    再次启动时,发现还缺一个库文件。

    ./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
    

    我们继续查找库文件。

    1. [root@server bin]# find / -name libtinfo.so*
    2. /usr/lib64/libtinfo.so.6
    3. /usr/lib64/libtinfo.so.6.2

    发现也是缺少一个对应的5版本的文件,同样的道理,将对应的高版本创建一个低版本的软连接。

    [root@server bin]# ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
    

  • 相关阅读:
    智能测量设备校准的重要性
    计算机毕业设计ssm企业员工信息管理系统677du系统+程序+源码+lw+远程部署
    数据结构--》解锁数据结构中树与二叉树的奥秘(二)
    智慧园区SaaS管理系统解决方案:赋能园区实现信息化、数字化管理
    缓存穿透的解决办法有哪些?
    Python Fire:更加灵活的命令行参数
    【网络爬虫】2 初探网络爬虫
    pagmo并行全局多目标优化算法库的安装编译与使用
    Web3.0时代的全新合作模式:DAO
    Linq to SQL语句之DataContext
  • 原文地址:https://blog.csdn.net/white1114579650/article/details/134416493