Linux下安装mysql8的方法

  1. cd /usr/local/pkg

  2. 下载Linux-Generic版本: https://dev.mysql.com/downloads/mysql/

    如:wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-i686.tar.xz

  3. tar -xvf mysql-8.0.17-linux-glibc2.12-i686.tar.xz //解压安装包

    此处,如果出现如下错误:
    tar (child): xz: Cannot exec: No such file or directory
    tar (child): Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now
    说明:缺少xz工具,如下教程安装xz
    安装XZ工具
    安装成功后,执行:tar -xvf mysql-8.0.17-linux-glibc2.12-i686.tar.xz

  4. mv mysql-8.0.17-linux-glibc2.12-i686 /usr/local/mysql //移动到/usr/local/mysql目录

  5. 创建用户和组,并改变mysql目录的拥有者:

    groupadd mysql
    useradd -r -g mysql mysql
    chown -R mysql:mysql /usr/local/mysql

  6. Linux下mysql配置文件的默认位置在/etc/my.cnf, 建立文件, 写如下信息

    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    socket=/usr/local/mysql/mysql.sock
    user=mysql
    symbolic-links=0
    [mysqld_safe]
    log-error=/usr/local/mysql/mysqld.log
    pid-file=/usr/local/mysql/mysqld/mysqld.pid

  7. 初始化数据库, 到/usr/local/mysql/bin目录下执行: ./mysqld --initialize --user=mysql
    随后会生成一个root临时密码,如:A temporary password is generated for root@localhost: FW+He5#fh1e1

    此处,如果出现如下错误:
    ./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
    说明,缺少:numactl 工具
    执行 yum -y install numactl
    安装成功后,执行:./mysqld --initialize --user=mysql

  8. 启动mysql: 也可后台运行, 即在命令后加 &
    ./mysqld --user=mysql &

  9. 使用第7步中生成的临时密码登录
    ./mysql -uroot -p 回车, 输入临时密码

    此处,如果出现如下错误:
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
    执行如下命令:
    ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
    执行成功后, 再执行:./mysql -uroot -p

  10. 修改密码, alter user 'root'@'localhost' identified by '123456';

  11. 支持运程访问:create user 'root'@'%' identified by '123456';

  12. 配置所有权限: grant all on *.* to 'root'@'%';

至此, MySQL 8.0的安装配置就完成了.

Logo

更多推荐