mysql5.7二进制安装(linux下mysql二进制安装附资料及配置文件)

一、准备资料

  • 资料
    在这里插入图片描述
  • 环境

    操作系统 CentOS7.6
    数据库:mysql-5.7.29-linux-glibc2.12-x86_64(二进制文件)

二、准备工作

  • 安装mysql依赖扩展
    yum -y install ncurses-devel  libaio-devel
    
  • 创建mysql组及用户
    [root@NGINX ~]# groupadd mysql
    [root@NGINX ~]# useradd -s /sbin/nologin -g mysql -M mysql
    
  • 上传mysql文件至家目录
    上传文件并解压
    [root@NGINX ~]# tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz 
    [root@NGINX ~]# mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql
    ##
    [root@NGINX ~]# mkdir /usr/local/mysql/data -p
    [root@NGINX ~]# chown mysql.mysql /usr/local/mysql/data/
    [root@NGINX ~]# chown mysql.mysql /usr/local/mysql/ -R
    
    

三、安装

  • 初始化数据库
    [root@NGINX ~]#/usr/local/mysql/bin/mysqld --initialize \
    --basedir=/usr/local/mysql/ \
    --datadir=/usr/local/mysql/data/ --user=mysql
    
  • 提示如下说明初始化成功
2020-02-03T17:19:21.885268Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-03T17:19:22.145932Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-02-03T17:19:22.205145Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-03T17:19:22.266136Z 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: 51b82412-46a9-11ea-a597-000c299d5ffd.
2020-02-03T17:19:22.267329Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-03T17:19:23.113327Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-03T17:19:23.426412Z 1 [Note] A temporary password is generated for root@localhost: axOIZ8YqgG?;
  • 配置环境变量
[root@NGINX ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile
[root@NGINX ~]# source /etc/profile
  • 配置服务
[root@NGINX ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@NGINX ~]# service mysql start
Starting MySQL.2020-02-03T17:28:22.352928Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/var/lib/mysql/NGINX.pid).
###添加些日志权限修改pid文件写权限


  • 故障处理全过程
[root@NGINX ~]# service mysql start
Starting MySQL.2020-02-03T17:28:22.352928Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/var/lib/mysql/NGINX.pid).
[root@NGINX ~]# mkdir /var/log/mariadb/ -p
[root@NGINX ~]# echo ''>/var/log/mariadb/mariadb.log|xargs chown mysql.mysql
chown: missing operand after ‘mysql.mysql’
Try 'chown --help' for more information.
[root@NGINX ~]# ^C
[root@NGINX ~]# mkdir /var/log/mariadb/ -p
[root@NGINX ~]# echo ''>/var/log/mariadb/mariadb.log
[root@NGINX ~]# chown mysql.mysql /var/log/mariadb/mariadb.log
[root@NGINX ~]# chown mysql.mysql /var/lo
local/ lock/  log/   
[root@NGINX ~]# chown mysql.mysql /var/log/mysql
chown: cannot access ‘/var/log/mysql’: No such file or directory
[root@NGINX ~]# mkdir /var/log/mysql
[root@NGINX ~]# chown mysql.mysql /var/log/mysql
[root@NGINX ~]# service mysql start
Starting MySQL.2020-02-03T17:38:15.918258Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
 ERROR! The server quit without updating PID file (/var/lib/mysql/NGINX.pid).
[root@NGINX ~]# mkdir /var/lib/mysql
[root@NGINX ~]# chown mysql.mysql /var/lib/mysql
[root@NGINX ~]# service mysql start
Starting MySQL..... ERROR! The server quit without updating PID file (/var/lib/mysql/NGINX.pid).
###还是启动不起来发现my.cnf中datadir没有修改将datadir=/var/lib/mysql
###改成/usr/local/mysql/data
[root@NGINX ~]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
"/etc/my.cnf" 19L, 578C written
[root@NGINX ~]# service mysql start
Starting MySQL. SUCCESS! 
  • 服务已经成功起来
    在这里插入图片描述

  • 连接数据库
    依旧很坎坷

[root@NGINX ~]# netstat -nutpl|grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      22763/mysqld        
[root@NGINX ~]# mysql -uroot -paxOIZ8YqgG?;
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@NGINX ~]# ln -s /var/lib/mysql.sock /tmp/mysql.sock
[root@NGINX ~]# mysql -uroot -paxOIZ8YqgG?;
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
##找不到sock由于没指定sock登录 可在默认路径添加sock链接
##/var/lib/mysql/mysql.sock 为本人实例sock路径不清楚的用户可参考
##/etc/my.cnf中的配置
[root@NGINX ~]# ln -s /var/lib/mysql.sock /tmp/mysql.sock
[root@NGINX ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
ln: failed to create symbolic link ‘/tmp/mysql.sock’: File exists
[root@NGINX ~]# rm /tmp/mysql.sock 
rm: remove symbolic link ‘/tmp/mysql.sock’? y
[root@NGINX ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@NGINX ~]# mysql -uroot -paxOIZ8YqgG?;
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@NGINX ~]# mysql -uroot -paxOIZ8YqgG?
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@NGINX ~]# /usr/local/mysq/bin/mysql -uroot -paxOIZ8YqgG?;
-bash: /usr/local/mysq/bin/mysql: No such file or directory
[root@NGINX ~]# /usr/local/mysql/bin/mysql -uroot -paxOIZ8YqgG?;
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@NGINX ~]# 
###密码也进不去了 看来我还要破解密码。。。
  • mysql数据库密码忘记找回
[root@NGINX ~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
[1] 24488
[root@NGINX ~]# 2020-02-03T18:24:19.611951Z mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
2020-02-03T18:24:19.643658Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@NGINX ~]# netstat -nutpl |grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      24638/mysqld        
[root@NGINX ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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("Cmm111111%%");
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> update mysql.user set authentication_string=password("Cmm111111%%") where user='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush priliveges;
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 'priliveges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
[root@NGINX ~]# netstat -nutpl |grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      24638/mysqld        
[root@NGINX ~]# killall mysqld
[root@NGINX ~]# 2020-02-03T18:31:40.272008Z mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended

[1]+  Done                    /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql
[root@NGINX ~]# netstat -nutpl |grep 330
[root@NGINX ~]# service mysql start
Starting MySQL. SUCCESS! 
[root@NGINX ~]# /usr/local/mysql/bin/mysql -uroot -pCmm111111%%
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
##破解密码后首次进入操作需要执行如下操作
mysql> set password=password("Cmm111111%%");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

END

资料下载

关注公众号: 扣丁曼 回复“mysql57”获取素材下载链接。

猜你喜欢

转载自blog.csdn.net/Qcg0223/article/details/104158792