mysql5.7二进制安装

mysql 2018-12-04 浏览(865 评论(0

mysql5.7二进制安装

mkdir -p /data/www                      #创建数据库文件保存目录
chown -R www:www /data/www/             #设置目录所有者
chmod -R 700 /data/www                  #设置目录权限

useradd mysql -s /sbin/nologin          #创建用户mysql,不允许直接登录系统
mkdir -p /var/mysql/data                #创建Mysql数据库存放目录
chown -R mysql:mysql /var/mysql/data    #设置Mysql数据库目录权限


到下载目录,下载并解压安装文件:
    cd /lnmp/src
    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
复制文件并创建mysql文件:
    cp -r mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
进入安装目录:
    cd /usr/local/mysql
授权:
    chown -R mysql:mysql /usr/local/mysql
验证权限:
    ll
编辑参数文件:
    vim /etc/my.cnf
        [client]
        port = 3306
        socket = /tmp/mysql.sock
        [mysqld]
        server_id=10
        port = 3306
        user = mysql
        character-set-server = utf8mb4
        default_storage_engine = innodb
        log_timestamps = SYSTEM
        socket = /tmp/mysql.sock
        basedir = /usr/local/mysql
        datadir = /var/mysql/data
        pid-file = /var/mysql/data/mysql.pid
        max_connections = 1000
        max_connect_errors = 1000
        table_open_cache = 1024
        max_allowed_packet = 128M
        open_files_limit = 65535
        #####====================================[innodb]==============================
        innodb_buffer_pool_size = 1024M
        innodb_file_per_table = 1
        innodb_write_io_threads = 4
        innodb_read_io_threads = 4
        innodb_purge_threads = 2
        innodb_flush_log_at_trx_commit = 1
        innodb_log_file_size = 512M
        innodb_log_files_in_group = 2
        innodb_log_buffer_size = 16M
        innodb_max_dirty_pages_pct = 80
        innodb_lock_wait_timeout = 30
        innodb_data_file_path=ibdata1:1024M:autoextend
        innodb_undo_tablespaces=3
        #####====================================[log]==============================
        log_error = /mysql/log/mysql-error.log 
        slow_query_log = 1
        long_query_time = 1 
        slow_query_log_file = /mysql/log/mysql-slow.log
        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
安装数据库:
    ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/var/mysql/data
    
    注:[Note] A temporary password is generated for root@localhost: Zqxv6RhOjt&7(这是默认密码,首次登录需要用到)
查看默认密码
    grep -i password /mysql/log/mysql-error.log
    
    A temporary password is generated for root@localhost: Zqxv6RhOjt&7(这是默认密码,首次登录需要用到)
配置环境变量:
    vi /etc/profile                                          #把mysql服务加入系统环境变量:在最后添加下面这一行
    export PATH=$PATH:/usr/local/mysql/bin
    source /etc/profile 
配置启动文件并设置开机启动:
    cp support-files/mysql.server /etc/init.d/mysql
    chkconfig mysql on
    service mysql start
进入mysql:
    mysql -uroot -pZqxv6RhOjt&7
    登录之后需要重置密码,不然会一直提示:You must reset your password using ALTER USER statement before executing this statement.
重置密码:
    1.使用alter修改
        mysql> ALTER USER USER() IDENTIFIED BY 'Mysql123!@#$';
        Query OK, 0 rows affected (0.00 sec)
        或者
        mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql123!@#$';  #针对localhost
        Query OK, 0 rows affected (0.00 sec)
    2.使用set password
        mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Mysql123!@#$');  
        Query OK, 0 rows affected, 1 warning (0.00 sec)
         
        mysql> flush privileges;
        Query OK, 0 rows affected (0.00 sec)
    3.使用update
        mysql> UPDATE mysql.user SET authentication_string = PASSWORD('Mysql123!@#$'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
        Query OK, 1 row affected, 1 warning (0.00 sec)
         
        mysql> flush privileges;
        Query OK, 0 rows affected (0.00 sec)
到此,mysql就安装完成了,可以开始使用了。


打赏

如果此文对你有所帮助,请随意打赏鼓励作者^_^

黄信强博客