Linux安装mysql5.7

下载mysql5.7

下载地址:https://dev.mysql.com/downloads/mysql/,或直接用wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 下载,如图

Linux安装mysql5.7_第1张图片

将下载的包复制到linux/data/software目录下

安装

1 解压:tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
2 复制到/usr/local下并修改文件夹名:mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
3 创建mysql用户组组:groupadd mysql 
4 创建mysql用户并添加到mysql用户组中:useradd -r -g mysql mysql
5 将mysql目录访问权限赋为myql用户:chown -R mysql /usr/local/mysql/
6 改变mysql目录的用户组属于mysql组:chgrp -R mysql /usr/local/mysql/
7 创建配置文件:vi /etc/my.cnf
    [client]
    port = 3306
    socket = /tmp/mysql.sock

    [mysqld]
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    socket=/tmp/mysql.sock
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    lower_case_table_names = 1
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISIO	N_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    max_connections=5000
    default-time_zone = '+8:00'   

复制后保存退出

8 安装依赖的libaio包:  yum install libaio
9 创建mysql日志文件:vi /var/log/mysqld.log 
10 修改日志文件读写权限:chmod 777 /var/log/mysqld.log
11 修改日志文件所属用户和组:chown mysql:mysql /var/log/mysqld.log
12 初始化数据库:/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
13 查看mysql初始密码:more /var/log/mysqld.log(最后一行“root@localhost:”后就是)
14 启动mysql:service mysqld start
   如果报错:/usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
     解决:1 cd /var/run/
           2 mkdir mysqld
           3 chown -R mysql /var/run/mysqld
           4 chgrp -R mysql /var/run/mysqld
           5 service mysqld start
15 用命令行进入mysql:mysql -u root -p 
16 修改root密码:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
17 建立远程用户orange:grant all privileges on *.* to 'orange'@'%' identified by 'orange';
18 在本机就能用orange用户连接数据库了

你可能感兴趣的:(数据库)