zoukankan      html  css  js  c++  java
  • centos7安装mysql8

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

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

    卸载centos7中自带的mariadb

    [root@localhost ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.56-2.el7.x86_64
    [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格式的,需要先解压、再解包。

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

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

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

    创建mysql用户

    [root@CentOS7-1 mysql]# useradd mysql
    [root@CentOS7-1 mysql]# passwd mysql
    ……密码相关提示操作……

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

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

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

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

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

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

      

     将mysql添加到服务

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

    配置环境变量/etc/profile

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

    启动mysql

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

    登录mysql

    [root@localhost bin]# mysql -uroot -p
    Enter password: 输入初始化时生成的密码
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.20
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    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> 

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

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

    alter语句中,WITH mysql_native_password是为了可以通过sqlyog等mysql客户端连接,否则会报加密错误。

  • 相关阅读:
    liunx 解压与压缩
    缓存设计与优化
    易混乱javascript知识点简要记录
    初识RedisCluster集群
    Redis Sentinel(哨兵模式)
    JavaScript作用域简单记录
    JavaScript引用类型简单记录
    redis主从复制初识
    javascript基础知识点
    持久化的一些问题
  • 原文地址:https://www.cnblogs.com/Forever77/p/15658189.html
Copyright © 2011-2022 走看看