zoukankan      html  css  js  c++  java
  • centos7 安装mysql5.7(二进制tar包方式)

    1、解压
    [root@localhost ~]# tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
    2、移动重命名
    [root@localhost ~]# mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
    3、创建mysql用户及目录
    [root@localhost local]# mkdir -p /data/mysql
    [root@localhost local]# groupadd mysql
    [root@localhost local]# useradd -r -g mysql mysql
    [root@localhost local]# chown mysql:mysql -R /data/mysql
    [root@localhost local]# ll
    [root@localhost local]# ll /data/
    total 0
    drwxr-xr-x. 2 mysql mysql 6 Apr 4 14:47 mysql
    4、更改配置文件

    [mysqld]
    bind-address=0.0.0.0
    port=3306
    user=mysql
    basedir=/usr/local/mysql
    datadir=/data/mysql
    socket=/tmp/mysql.sock
    log-error=/data/mysql/mysql.err
    pid-file=/data/mysql/mysql.pid
    #character config
    #character_set_server=utf8mb4
    #symbolic-links=0
    #explicit_defaults_for_timestamp=true


    5、初始化mysql (/data/mysql/mysql.err有随机产生的口令)
    [root@localhost bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
    [root@localhost bin]# cat /data/mysql/mysql.err
    2020-04-04T06:50:24.172946Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-04-04T06:50:24.650600Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-04-04T06:50:25.108776Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-04-04T06:50:25.323095Z 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: 8ff259ef-7640-11ea-b454-000c29a11c85.
    2020-04-04T06:50:25.325678Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-04-04T06:50:25.341337Z 1 [Note] A temporary password is generated for root@localhost: inB6TOM;v#r_
    6、将mysql.server 拷贝到init.d下
    [root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql、
    [root@localhost bin]#
    [root@localhost bin]# service mysql start

    [root@localhost mysql]# ps -ef|grep mysql
    root 108186 1 0 15:00 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
    mysql 108377 108186 0 15:00 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
    root 108441 32810 0 15:03 pts/2 00:00:00 grep --color=auto mysql
    7、登录mysql更改root密码并设置不失效
    [root@localhost bin]# ./mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.7.22

    Copyright (c) 2000, 2018, 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>
    mysql> SET PASSWORD = PASSWORD('123456'); #更改密码
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; #设置密码不失效
    Query OK, 0 rows affected (0.00 sec)

    mysql>
    mysql> FLUSH PRIVILEGES; #刷新权限
    Query OK, 0 rows affected (0.00 sec)

    mysql> use mysql 选择数据库名为MySQL的库
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql>
    mysql> update user set host = '%' where user = 'root'; 更改root用户能用任何主机名登录数据库
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql>
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)


    8、配置root能直接使用mysql命令登录
    [root@localhost bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin
    如果创建失败可以先把/usr/bin/mysql删除再创建软连接

  • 相关阅读:
    DB2 9 使用斥地(733 考试)认证指南,第 5 局部: CLI/ODBC 编程(3)
    DB2 9 操作开发(733 测验)认证指南,第 8 部分: 初级编程(5)
    DB2 9 哄骗开辟(733 测验)认证指南,第 5 部门: CLI/ODBC 编程(4)
    DB2 9 运用斥地(733 检验)认证指南,第 7 部分: Java 编程(4)
    DB2 9 使用开发(733 检验)认证指南,第 5 部门: CLI/ODBC 编程(5)
    DB2 9 运用斥地(733 考试)认证指南,第 7 局部: Java 编程(1)
    DB2 9 运用启示(733 考试)认证指南,第 8 部门: 低级编程(2)
    DB2 9 哄骗开荒(733 考试)认证指南,第 8 局部: 低级编程(7)
    DB2 9 利用斥地(733 考试)认证指南,第 6 部门: .NET 编程(6)
    DB2 9 哄骗开发(733 考试)认证指南,第 5 局部: CLI/ODBC 编程(6)
  • 原文地址:https://www.cnblogs.com/Wardenking/p/12632013.html
Copyright © 2011-2022 走看看