zoukankan      html  css  js  c++  java
  • linux(CentOS7) 之 MySQL 5.7.30 下载及安装

    一、下载

    1、百度搜索mysql,进入官网(或直接进入官网https://www.mysql.com

     

    2、选择 downloads

     

    3、翻到最下面,选择MySQL Community (GPL) Downloads

     

    4、选择MySQL Community Server

     

    5、选择archives(历史版本)

     

    6、选择相应操作系统、版本 ,点击download 下载

     

    二、安装

    1、配置规划

    压缩包存放路径: /opt/software

    安装目录: /usr/local/mysql

    数据文件目录: /usr/local/mysql/data

    占用端口:3306

    默认socket文件存放路径: /tmp/mysql.sock 客户端与服务器端通信的套接字文件

    2、解压:

    cd /opt/software
    tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

    3、重命名mysql-5.7.30-linux-glibc2.12-x86_64为mysql

    mv /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql

    4、创建数据目录

    mkdir /usr/local/mysql/data

    5、创建mysql用户,只用于配置mysql,无登录权限

    useradd -r -s /sbin/nologin mysql

    6、更改/usr/local/mysql 目录权限给mysql

    chown -R mysql.mysql /usr/local/mysql

    7、初始化数据库

    在/usr/local/mysql目录下执行初始化操作

    注意:会生成一个临时密码,后面登录数据库会用到,记下来。PW-f?>wLp8wv

    [root@bogon mysql]#cd /usr/local/mysql
    [root@bogon mysql]#bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    2021-04-03T12:58:00.784162Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2021-04-03T12:58:00.953286Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2021-04-03T12:58:00.977791Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2021-04-03T12:58:01.034994Z 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: 3889e932-947c-11eb-85e1-000c29cabcf2.
    2021-04-03T12:58:01.035793Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2021-04-03T12:58:01.379465Z 0 [Warning] CA certificate ca.pem is self signed.
    2021-04-03T12:58:01.454994Z 1 [Note] A temporary password is generated for root@localhost: PW-f?>wLp8wv # 临时密码

    8、初始化ssl

    [root@bogon mysql]# bin/mysql_ssl_rsa_setup

    9、创建my.cnf配置文件

    先备份原有的my.cnf

    cp /etc/my.cnf /etc/my.cnf.old

     修改/etc/my.cnf

    vi /etc/my.cnf

    [mysqld]

    basedirr=/usr/local/mysql

    datadir=/usr/local/data

    10、mysql 启动配置

    复制配置文件 mysql.server 到 /etc/init.d

    cd /usr/local/mysql
    cp support-files/mysql.server /etc/init.d/mysqld

    给所有用户赋予可执行权限

    chmod a+x /etc/init.d/mysqld

    设置为开机启动

    chkconfig --add /etc/init.d/mysqld
    chkconfig mysqld on

    11、启动mysql服务

    service mysqld start

    mysql服务其他操作

    查看mysql状态  service mysqld status
    
    停止mysql服务  service mysqld status
    
    重启mysql服务  service mysqld restart

    12、配置环境变量

    echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

    让配置生效

    source /etc/profile

    13、登录mysql

    mysql -uroot -pqoge.eC#l9Wg

    14、重置密码

    alter user root@'localhost' identified by '123';

    15、重新登录

    mysql -uroot -p123

    16、查看数据库版本

    select version;

    三、重新初始化

    若忘记了临时密码或意外删除了/usr/local/mysql目录等其他原因,可重新初始化。

    1、停掉mysql服务

    service mysqld stop

    2、删除/usr/local/mysql/data 目录

    rm -rf /usr/local/mysql/data

    3、给目录赋权

    chown -R mysql.mysql /usr/local/mysql

    4、重新初始化

    [root@bogon mysql]#bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

    5、重新初始化ssl

    [root@bogon mysql]# bin/mysql_ssl_rsa_setup

     

    世风之狡诈多端,到底忠厚人颠扑不破; 末俗以繁华相尚,终觉冷淡处趣味弥长。
  • 相关阅读:
    nodejs express搭建一个网站整理
    nodejs http post 请求带参数
    express respond.send 和 end的区别
    .net程序员做的第一个安卓APP
    angularjs ui-grid如何动态设置行高
    错误处理(Operation Result)方法
    jquery validation yyyy-MM-dd格式日期在ie中无法验证通过
    PAT (Basic Level) Practise (中文)- 1010. 一元多项式求导 (25)
    PAT (Basic Level) Practise (中文)- 1007. 素数对猜想 (20)
    PAT (Basic Level) Practise (中文)- 1012. 数字分类 (20)
  • 原文地址:https://www.cnblogs.com/simple-li/p/14615065.html
Copyright © 2011-2022 走看看