2进制安装MySQL
第1步进入这个官网
https://www.mysql.com/downloads/
第2步找到这个点一下
MySQL Community (GPL) Downloads »
第3步找到这个点一下
Download Archives
第4步找到社区版的服务器点一下
MySQL Community Server
用5.7免费的最新版本,选用linux-Generic(linux通用),用OS(操作系统)64位系统,除了中间不能用,其他包都可以用
[root@hm1 src]# useradd -r -M -s /sbin/nologin mysql [root@hm1 src]# id mysql uid=975(myaql) gid=973(myaql) 组=973(myaql) [root@hm1 src]# ls /usr/local/ bin etc games include lib lib64 libexec sbin share src [root@hm1 src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@hm1 src]# cd /usr/local/ [root@hm1 local]# ls bin games lib libexec sbin src etc include lib64 mysql-5.7.37-linux-glibc2.12-x86_64 share [root@hm1 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql [root@hm1 local]# ls bin etc games include lib lib64 libexec mysql sbin share src //修改目录账户属主属组 [root@hm1 local]# chown -R mysql.mysql mysql [root@hm1 local]# ll -d mysql/ drwxr-xr-x. 9 mysql mysql 129 6月 28 15:41 mysql/ //添加环境变量,叫他在那个目录找MySQL [root@hm1 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh //读取 [root@hm1 local]# source /etc/profile.d/mysql.sh [root@hm1 local]# which mysql /usr/local/mysql/bin/mysql
有特定的目录的时候,要修改
include(头文件)
man(帮助文档)
lib(库)
bin(主程序)
//设置软链接,里面有多个文件,以后好直接删除目录
[root@hm1 mysql]# cd /usr/local/mysql
[root@hm1 mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
//告诉他头文件库在那个地方
[root@hm1 mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@hm1 mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@hm1 mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
//读取配置文件
[root@hm1 mysql]# ldconfig
//告诉他man文档在那个地方
[root@hm1 mysql]# vim /etc/man_db.conf
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
//加上这一行
MANDATORY_MANPATH /usr/local/mysql/man
#---------------------------------------------------------
# set up PATH to MANPATH mapping
# ie. what man tree holds man pages for what binary directory.
//建立数据存放目录
在企业,设置数据存放目录要放在存储空间大的目录
[root@hm1 ~]# mkdir -p /opt/data
[root@hm1 ]# chown -R mysql.mysql /opt/data/
[root@hm1 ~]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 6月 28 18:39 /opt/data/
//mysqld 系统知道mysql在哪就不用加路径
[root@hm1 ~]# mysqld --initialize --user mysql --datadir /opt/data
2022-06-28T10:40:51.279183Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-06-28T10:40:52.695768Z 0 [Warning] CA certificate ca.pem is self signed.
2022-06-28T10:40:52.909685Z 1 [Note] A temporary password is generated for root@localhost: jysro6OtPi)o
[root@hm1 ~]# echo "jysro6OtPi" > pass
[root@hm1 ~]#
//生成配置文件
[root@localhost】 vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
# sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@hm1 ~]# cd /usr/local/mysql/support-files/
[root@hm1 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@hm1 support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable
[root@hm1 support-files]# ll
总用量 24
-rw-r--r--. 1 mysql mysql 773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 1061 11月 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 894 11月 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 30 2021 mysql.server
[root@hm1 support-files]# cp mysql.server mysqld
[root@hm1 support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql 773 11月 30 2021 magic
-rwxr-xr-x. 1 root root 10576 6月 28 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql 1061 11月 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 894 11月 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 30 2021 mysql.server
[root@hm1 support-files]# chown -R mysql.mysql mysqld
[root@hm1 support-files]# ll
总用量 36
-rw-r--r--. 1 mysql mysql 773 11月 30 2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 6月 28 18:57 mysqld
-rwxr-xr-x. 1 mysql mysql 1061 11月 30 2021 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 894 11月 30 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 11月 30 2021 mysql.server
[root@hm1 support-files]# vim mysqld
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
//改这个地方
basedir=/usr/local/mysql
datadir=/opt/data
[root@hm1 ~]# /usr/local/mysql/support-files/mysqld start
Starting MySQL.Logging to '/opt/data/hm1.err'.
SUCCESS!
[root@hm1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
[root@hm1 ~]# ps -ef|grep mysqld
root 411797 1 0 19:01 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/hm1.pid
//报错缺少东西
[root@hm1 ~]# mysql -uroot -p'jysro6OtPi'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//查找东西来源那个包
[root@hm1 ~]# dnf provides libncurses.so.5
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:40:31 前,执行于 2022年06月28日 星期二 18时25分34秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
仓库 :base
匹配来源:
提供 : libncurses.so.5
//安装包
[root@hm1 ~]# dnf -y install ncurses-compat-libs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:42:51 前,执行于 2022年06月28日 星期二 18时25分34秒。
[root@hm1 ~]# cat pass
x7GkcGDZ0h(d
[root@hm1 ~]# mysql -uroot -p'x7GkcGDZ0h(d'
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.37
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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('runtime123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@hm1 ~]# mysql -uroot -p'runtime123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
//设置开机自启
//关闭selinux
[root@hm1 ~]# setenforce 0
[root@hm1 ~]# vim /etc/selinux/config
[root@hm1 ~]# ll -Z /usr/lib/systemd/system/{sshd.service,mysqld.service}
//admin_home报文 selinux无法识别,所以会报错,所有要关闭selinux
-rw-r--r--. 1 root root unconfined_u:object_r:admin_home_t:s0 283 6月 28 20:27 /usr/lib/systemd/system/mysqld.service
-rw-r--r--. 1 root root system_u:object_r:sshd_unit_file_t:s0 456 1月 9 2020 /usr/lib/systemd/system/sshd.service
[root@hm1 ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HDP $MATNPID
[root@hm1 ~]# systemctl daemon-reload
[root@hm1 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
Active: inactive (dead)
[root@hm1 ~]# systemctl start mysqld
[root@hm1 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor >
Active: active (running) since Tue 2022-06-28 20:49:53 CST; 1s ago
Process: 512182 ExecStart=/usr/local/mysql/support-files/mysqld start (cod>
[root@hm1 ~]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
设置免密码隐藏登录
//必须要在家目录下创建 [root@hm1 ~]# vim .my.cnf [root@hm1 ~]# cat .my.cnf [client] user = root password = runtime123 [root@hm1 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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> quit Bye密码破解
[root@hm1 ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
skip-grant-tables
# sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@hm1 ~]# systemctl restart mysqld
[root@hm1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> use mysql;
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
//查看表信息
mysql> select * from userG
mysql> update user set authentication_string = password('123456') where User = 'root' and Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> quit
Bye
[root@hm1 ~]#



