mysql应用1

mysql进阶

二进制安装mysql

下载二进制软件包
https://downloads.mysql.com/archives/community/

[root@zzz ~]# ls
file  ifcfg-ens33                                 outfile  ss
home  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  passwd   yyds

创建组,用户

[root@zzz ~]# groupadd -r mysql
[root@zzz ~]# useradd -M -s /sbin/nologin  -r -g mysql mysql
[root@zzz ~]# id mysql
uid=994(mysql) gid=665(mysql) groups=665(mysql)

解压软件包

[root@zzz ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@zzz ~]# cd /usr/local/
[root@zzz local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@zzz local]# 

设置软链接

[root@zzz local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/  mysql
[root@zzz local]# ll
total 0
drwxr-xr-x. 2 root root   6 May 11  2019 bin
drwxr-xr-x. 2 root root   6 May 11  2019 etc
drwxr-xr-x. 2 root root   6 May 11  2019 games
drwxr-xr-x. 2 root root   6 May 11  2019 include
drwxr-xr-x. 2 root root   6 May 11  2019 lib
drwxr-xr-x. 2 root root   6 May 11  2019 lib64
drwxr-xr-x. 2 root root   6 May 11  2019 libexec
lrwxrwxrwx. 1 root root  36 Jul 27 05:30 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 27 05:28 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 11  2019 sbin
drwxr-xr-x. 5 root root  49 Jun 28 02:50 share
drwxr-xr-x. 2 root root   6 May 11  2019 src
[root@zzz local]# 

更改文件属主属组

[root@zzz local]# chown -R mysql.mysql /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/
[root@zzz local]# chown -R mysql.mysql /usr/local/mysql
[root@zzz local]# ll
total 0
drwxr-xr-x. 2 root  root    6 May 11  2019 bin
drwxr-xr-x. 2 root  root    6 May 11  2019 etc
drwxr-xr-x. 2 root  root    6 May 11  2019 games
drwxr-xr-x. 2 root  root    6 May 11  2019 include
drwxr-xr-x. 2 root  root    6 May 11  2019 lib
drwxr-xr-x. 2 root  root    6 May 11  2019 lib64
drwxr-xr-x. 2 root  root    6 May 11  2019 libexec
lrwxrwxrwx. 1 mysql mysql  36 Jul 27 05:30 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Jul 27 05:28 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 May 11  2019 sbin
drwxr-xr-x. 5 root  root   49 Jun 28 02:50 share
drwxr-xr-x. 2 root  root    6 May 11  2019 src
[root@zzz local]# 

设置环境变量

[root@zzz local]# cd mysql
[root@zzz mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@zzz mysql]# pwd
/usr/local/mysql
[root@zzz mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >/etc/profile.d/mysql.sh
[root@zzz bin]# cat /etc/profile.d/mysql.sh 
export PATH=$PATH:/usr/local/mysql/bin
[root@zzz bin]# bash
[root@zzz bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@zzz bin]# 

设置include软链接

[root@zzz bin]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@zzz bin]# ll /usr/include/
total 0
lrwxrwxrwx. 1 root root 25 Jul 27 05:48 mysql -> /usr/local/mysql/include/
drwxr-xr-x. 2 root root 27 Jun 28 02:50 python3.6m

设置lib

[root@zzz bin]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib


"/etc/ld.so.conf.d/mysql.conf" 1L, 21C                           1,20          All
[root@zzz bin]# ldconfig

设置man

编写/etc/man_db.conf 在其中添加
MANDATORY_MANPATH                       /usr/local/mysql/man

建立数据存放目录

[root@zzz mysql]# mkdir /opt/data
[root@zzz mysql]# chown -R mysql.mysql /opt/data/
[root@zzz mysql]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 Jul 27 05:55 /opt/data/
[root@zzz mysql]# 

初始化mysql

[root@zzz mysql]# mysqld --initialize --user=mysql --datadir=/opt/data

2022-07-26T21:57:17.449575Z 1 [Note] A temporary password is generated for root@localhost: JAqq3L6jXa+W     (临时密码)

root@zzz mysql]# cd 
[root@zzz ~]# echo 'JAqq3L6jXa+W' >passwd

(密码是随机生成,不是一样的)

生成配置文件

[root@zzz ~]# 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@zzz ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@zzz ~]# vim /etc/init.d/mysqld 
添加下列命令
basedir=/usr/local/mysql
datadir=/opt/data
退出保存
[root@zzz ~]# chkconfig --add mysqld
[root@zzz ~]# chkconfig mysqld on
[root@zzz ~]# 

启动mysql

[root@zzz ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/zzz.err'.
 SUCCESS! 
[root@zzz ~]# 

进入mysql

[root@zzz ~]# mysql -uroot -p'JAqq3L6jXa+W'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
这时候我们就需要下载libncurses.so.5

[root@zzz ~]# yum whatprovides libncurses.so.5
Last metadata expiration check: 14 days, 3:37:20 ago on Wed 13 Jul 2022 02:37:03 AM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : BaseOS
Matched from:
Provide    : libncurses.so.5

[root@zzz ~]# yum install -y ncurses-compat-libs

[root@zzz ~]# mysql -uroot -p'JAqq3L6jXa+W'
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> 
成功进入

更改密码
mysql> set password = password('@123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql配置文件

mysql的配置文件为/etc/my.cnf

配置文件查找次序:若在多个配置文件中均有设定,则最后找到的最终生效

/etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf

mysql常用配置文件参数:

参数说明
port = 3306设置监听端口
socket = /tmp/mysql.sock指定套接字文件位置
basedir = /usr/local/mysql指定MySQL的安装路径
datadir = /data/mysql指定MySQL的数据存放路径
pid-file =/data/mysql/mysql.pid指定进程ID文件存放路径
user = mysql指定MySQL以什么用户的身份提供服务
skip-name-resolve禁止MySQL对外部连接进行DNS解析使用这一选项可以消除MySQL进行DNS解析的时间。若开启该选项,则所有远程主机连接授权都要使用IP地址方式否则MySQL将无法正常处理连接请求

设置隐藏密码登录

[root@zzz ~]# vim .my.cnf

[client]
user=root
password=@123


[root@zzz ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
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> 

破解mysql密码

1.编译文件 /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(添加这条命令)跳过授权表

2.退出重齐mysql服务

[root@zzz ~]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
[root@zzz ~]# 

3.进入mysql更改密码

mysql> update user set authentication_string = Password('123456') where Host = 'localhost' and User = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> quit
Bye

4.退出删除跳过授权表命令
5.登录mysql验证

[root@zzz ~]# mysql -uroot -p123456
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 3
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> 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

seven凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值