CentOs7下安装mysql5.7

    xiaoxiao2021-03-25  114

    1.下载安装包

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

    2.解压

    tar -xf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

    3.

    ①groupadd mysql

     ②useradd -r -g mysql mysql

     * useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

     * useradd -g参数表示把mysql用户添加到mysql用户组中。

    4.复制

    cp mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql -r

    5.

    [root@localhost mysql]# cd /usr/local/mysql

    6.

    [root@localhost mysql]# chown -R mysql:mysql ./

    7.

    [root@localhost mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

    2017-03-10 10:37:34 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2017-03-10 10:37:37 [WARNING] The bootstrap log isn't empty: 2017-03-10 10:37:37 [WARNING] 2017-03-10T02:37:34.869429Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2017-03-10T02:37:34.869932Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2017-03-10T02:37:34.869938Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

    8.

    如果改变默认安装路径,则需要 1)/etc/my.cnf、/etc/init.d/mysqld中修改 basedir='/apps/mysql' datadir='/apps/mysql/data' 2)创建ln mkdir -p /usr/local/mysql/bin ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

    9

    [root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf [root@localhost mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld [root@localhost mysql]# cd bin [root@localhost bin]# ./mysqld_safe --user=mysql [root@localhost bin]#  /etc/init.d/mysqld restart Shutting down MySQL..2017-03-10T02:41:20.484909Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended  SUCCESS!  Starting MySQL. SUCCESS!  [1]+  完成                  ./mysqld_safe --user=mysql [root@localhost bin]# chkconfig --level 35 mysqld on [root@localhost bin]# cat /root/.mysql_secret  # Password set for user 'root@localhost' at 2017-03-10 10:37:34  Ta87m&HCemav [root@localhost bin]# ./mysql -uroot -p Enter password:  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@localhost bin]# ./mysql -uroot -p Enter password:  Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.17 Copyright (c) 2000, 2016, 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> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> use 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> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1  Changed: 1  Warnings: 0 mysql> select host, user from user; +-----------+-----------+ | host      | user      | +-----------+-----------+ | %         | root      | | localhost | mysql.sys | +-----------+-----------+ 2 rows in set (0.00 sec) mysql> /etc/init.d/mysqld restart     -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/etc/init.d/mysqld restart' at line 1 mysql> exit Bye [root@localhost bin]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS!  Starting MySQL. SUCCESS! 

    转载请注明原文地址: https://ju.6miu.com/read-19355.html

    最新回复(0)