美文网首页
linux下安装mysql-5.7.23(tar.gz)

linux下安装mysql-5.7.23(tar.gz)

作者: MrBryan | 来源:发表于2018-07-27 16:38 被阅读974次

    1、解压mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz,并拷贝到/usr/local/mysql目录下
    解压:

    tar -zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
    
    image.png

    拷贝:

    sudo cp -r mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
    
    $ sudo cp -r mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
    [sudo] password for work:
    

    2、添加系统mysql组和mysql用户
    添加系统mysql组

     sudo groupadd mysql
    

    添加mysql用户

    sudo useradd -r -g mysql mysql
    

    添加完成后可用id mysql查看

    $ id mysql
    uid=498(mysql) gid=501(mysql) groups=501(mysql)
    

    3、安装数据库

    • 切换到/usr/local/mysql目录
    cd /usr/local/mysql
    
    • 修改当前目录拥有者为mysql用户
    sudo chown -R mysql:mysql ./
    
    • 安装数据库(5.7版本的安装已经不建议使用mysql_install_db 来安装,而是使用mysqld
    sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    ]$ sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    2018-07-27T08:06:26.949667Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-07-27T08:06:27.257456Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2018-07-27T08:06:27.316545Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-07-27T08:06:27.374921Z 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: f64477d9-9173-11e8-99a4-fa163e9c2931.
    2018-07-27T08:06:27.377825Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2018-07-27T08:06:27.379223Z 1 [Note] A temporary password is generated for root@localhost: 2Dfiwj*ds8Ee
    

    临时密码:2Dfiwj*ds8Ee

    • 执行以下命令创建RSA private key
    sudo bin/mysql_ssl_rsa_setup  --datadir=/usr/local/mysql/data
    
    ]$ sudo bin/mysql_ssl_rsa_setup  --datadir=/usr/local/mysql/data
    Generating a 2048 bit RSA private key
    ..........................................................................................+++
    ......................................................................+++
    writing new private key to 'ca-key.pem'
    -----
    Generating a 2048 bit RSA private key
    .............................+++
    ..................+++
    writing new private key to 'server-key.pem'
    -----
    Generating a 2048 bit RSA private key
    ............................................................+++
    .....................................................................+++
    writing new private key to 'client-key.pem'
    -----
    
    
    • 修改当前目录拥有者为root用户
    sudo chown -R root:root ./
    
    • 修改当前data目录拥有者为mysql用户
    sudo chown -R mysql:mysql data
    
    ]$ sudo chown -R mysql:mysql data
    ]$ ls -las
    total 64
     4 drwxr-xr-x 10 root  root   4096 Jul 27 16:06 .
     4 drwxr-xr-x 13 root  root   4096 Jul 27 16:02 ..
     4 drwxr-xr-x  2 root  root   4096 Jul 27 16:02 bin
    20 -rw-r--r--  1 root  root  17987 Jul 27 16:02 COPYING
     4 drwxr-x---  5 mysql mysql  4096 Jul 27 16:07 data
     4 drwxr-xr-x  2 root  root   4096 Jul 27 16:02 docs
     4 drwxr-xr-x  3 root  root   4096 Jul 27 16:02 include
     4 drwxr-xr-x  5 root  root   4096 Jul 27 16:02 lib
     4 drwxr-xr-x  4 root  root   4096 Jul 27 16:02 man
     4 -rw-r--r--  1 root  root   2478 Jul 27 16:02 README
     4 drwxr-xr-x 28 root  root   4096 Jul 27 16:02 share
     4 drwxr-xr-x  2 root  root   4096 Jul 27 16:02 support-files
    
    

    4、配置my.cnf和开机启动

    cd support-files
    sudo cp my-default.cnf /etc/my.cnf
    sudo cp mysql.server /etc/init.d/mysql
    sudo vim /etc/init.d/mysql             ##修改basedir=  自己的路径     修改datadir= 自己的路径
    

    [图片上传失败...(image-ec874e-1532678468478)]

    [图片上传失败...(image-256588-1532678468478)]

    修改完毕后:wq!保存并退出vi
    vi命令:

    按ESC键 跳到命令模式,然后:
    :w 保存文件但不退出vi
    :w file 将修改另外保存到file中,不退出vi
    :w! 强制保存,不推出vi
    :wq 保存文件并退出vi
    :wq! 强制保存文件,并退出vi
    q: 不保存文件,退出vi
    :q! 不保存文件,强制退出vi
    :e! 放弃所有修改,从上次保存文件开始再编辑

    修改my.cnf

    sudo vim /etc/my.cnf
    

    [mysqld]
    character-set-server=utf8
    datadir=/home/mysql/mysqldata
    basedir=/usr/local/mysql
    socket=/var/lib/mysql/mysql.sock

    image.png

    保存并退出

    5、启动mysql

    sudo service mysql start
    

    6、登录mysql,并设置远程连接

    mysql -u user -p
    
    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
    flush privileges;
    

    </article>

    添加mysql 命令

    vi ~/.bash_profile
    
    添加
    export PATH=/usr/local/mysql/bin:$PATH
    

    修改密码:

    mysql -uroot -hlocalhost -P3306 -p
    set password = password('123456');
    

    相关文章

      网友评论

          本文标题:linux下安装mysql-5.7.23(tar.gz)

          本文链接:https://www.haomeiwen.com/subject/sfdgmftx.html