mysql进阶

mysql进阶

  • 1.下载二进制格式的mysql软件包
[root@mr ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mr ~]# cd /usr/src/
[root@mr src]# ls
debug  kernels  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@mr src]#

  • 2.创建用户和组,解压软件至/usr/local/,修改目录/usr/local/mysql的属主属组
[root@mr src]# id mysql
id: 'mysql': no such user
[root@mr src]# useradd -M -r -s /sbin/nologin mysql
[root@mr src]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)
[root@mr src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mr src]# cd /usr/local/
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root root  18 Jul  7 10:28 bin
drwxr-xr-x. 2 root root   6 May 19  2020 etc
drwxr-xr-x. 2 root root   6 May 19  2020 games
drwxr-xr-x. 2 root root   6 May 19  2020 include
drwxr-xr-x. 2 root root   6 May 19  2020 lib
drwxr-xr-x. 3 root root  17 Jul  1 09:26 lib64
drwxr-xr-x. 2 root root   6 May 19  2020 libexec
drwxr-xr-x. 9 root root 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 19  2020 sbin
drwxr-xr-x. 6 root root  64 Jul  7 10:28 share
drwxr-xr-x. 2 root root   6 May 19  2020 src
[root@mr local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64'
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root root  18 Jul  7 10:28 bin
drwxr-xr-x. 2 root root   6 May 19  2020 etc
drwxr-xr-x. 2 root root   6 May 19  2020 games
drwxr-xr-x. 2 root root   6 May 19  2020 include
drwxr-xr-x. 2 root root   6 May 19  2020 lib
drwxr-xr-x. 3 root root  17 Jul  1 09:26 lib64
drwxr-xr-x. 2 root root   6 May 19  2020 libexec
lrwxrwxrwx. 1 root root  35 Jul 27 16:04 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 19  2020 sbin
drwxr-xr-x. 6 root root  64 Jul  7 10:28 share
drwxr-xr-x. 2 root root   6 May 19  2020 src
[root@mr local]#
[root@mr local]# chown -R mysql.mysql mysql*
[root@mr local]# ll
total 0
drwxr-xr-x. 2 root  root   18 Jul  7 10:28 bin
drwxr-xr-x. 2 root  root    6 May 19  2020 etc
drwxr-xr-x. 2 root  root    6 May 19  2020 games
drwxr-xr-x. 2 root  root    6 May 19  2020 include
drwxr-xr-x. 2 root  root    6 May 19  2020 lib
drwxr-xr-x. 3 root  root   17 Jul  1 09:26 lib64
drwxr-xr-x. 2 root  root    6 May 19  2020 libexec
lrwxrwxrwx. 1 mysql mysql  35 Jul 27 16:04 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 Jul 27 16:03 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 May 19  2020 sbin
drwxr-xr-x. 6 root  root   64 Jul  7 10:28 share
drwxr-xr-x. 2 root  root    6 May 19  2020 src
[root@mr local]#

*
1. 添加环境变量

[root@mr ~]# cd /usr/local/mysql
[root@mr mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@mr mysql]# cd bin/
[root@mr bin]# pwd
/usr/local/mysql/bin
[root@mr bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@mr bin]# source /etc/profile.d/mysql.sh
[root@mr bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin
[root@mr bin]# which mysql
/usr/local/mysql/bin/mysql
[root@mr bin]#
[root@mr mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
'/usr/include/mysql' -> '/usr/local/mysql/include/'
[root@mr mysql]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib/
[root@mr mysql]# ldconfig
[root@mr mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man

*
1. 建立数据存放目录,初始化数据库

[root@mr ~]# mkdir /opt/data
[root@mr ~]# ll /opt/data/
total 0
[root@mr ~]# chown -R mysql.mysql /opt/data/
[root@mr ~]# mysqld --initialize --user mysql --datadir /opt/data/
2022-07-27T08:21:49.390169Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2022-07-27T08:21:49.520539Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-27T08:21:49.548430Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2022-07-27T08:21:49.557890Z 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: 29732c94-0d85-11ed-925a-000c29e8e4aa.

2022-07-27T08:21:49.558494Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2022-07-27T08:21:50.271098Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.

2022-07-27T08:21:50.271141Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.

2022-07-27T08:21:50.271798Z 0 [Warning] CA certificate ca.pem is self signed.

2022-07-27T08:21:50.425296Z 1 [Note] A temporary password is generated for root@localhost: -ff3uq#Fee%k
[root@mr ~]#
[root@mr ~]# echo '-ff3uq#Fee%k' > pass
[root@mr ~]# cat pass
-ff3uq#Fee%k

*
1. 生成配置文件

[root@mr ~]# 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

*
1. 配置服务启动脚本,启动mysql


[root@mr mysql]# cd support-files/
[root@mr support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@mr support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable
[root@mr support-files]#
方法一:
[root@mr ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/mr.err'.

 SUCCESS!

[root@mr ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:111            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22             0.0.0.0:*
LISTEN   0        25               0.0.0.0:514            0.0.0.0:*
LISTEN   0        80                     *:3306                 *:*
LISTEN   0        128                 [::]:111               [::]:*
LISTEN   0        128                 [::]:22                [::]:*
LISTEN   0        25                  [::]:514               [::]:*
[root@mr ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!

[root@mr ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:111            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22             0.0.0.0:*
LISTEN   0        25               0.0.0.0:514            0.0.0.0:*
LISTEN   0        128                 [::]:111               [::]:*
LISTEN   0        128                 [::]:22                [::]:*
LISTEN   0        25                  [::]:514               [::]:*
方法二:
[root@mr ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mr ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql/
datadir=/opt/data/
[root@mr ~]# service mysqld start
Starting MySQL. SUCCESS!

[root@mr ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!

[root@mr ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:111            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22             0.0.0.0:*
LISTEN   0        25               0.0.0.0:514            0.0.0.0:*
LISTEN   0        128                 [::]:111               [::]:*
LISTEN   0        128                 [::]:22                [::]:*
LISTEN   0        25                  [::]:514               [::]:*
[root@mr ~]# rm -rf /etc/init.d/mysqld
[root@mr ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit mysqld.service not found.

[root@mr ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
Failed to stop mysqld.service: Unit mysqld.service not loaded.

[root@mr ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:111            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22             0.0.0.0:*
LISTEN   0        25               0.0.0.0:514            0.0.0.0:*
LISTEN   0        128                 [::]:111               [::]:*
LISTEN   0        128                 [::]:22                [::]:*
LISTEN   0        25                  [::]:514               [::]:*
[root@mr ~]#

[root@mr ~]# cp /usr/lib/systemd/system/sshd.service .
[root@mr ~]# ls
 sshd.service
[root@mr ~]# mv sshd.service mysqld.service
[root@mr ~]# ls
mysqld.service
[root@mr ~]#vim mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@mr ~]# systemctl daemon-reload
[root@mr ~]# systemctl stop firewalld
[root@mr ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@mr ~]# vim /etc/selinux/config
SELINUX=disabled
[root@mr ~]# setenforce 0
[root@mr ~]# systemctl start mysqld
[root@mr ~]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:111            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22             0.0.0.0:*
LISTEN   0        25               0.0.0.0:514            0.0.0.0:*
LISTEN   0        80                     *:3306                 *:*
LISTEN   0        128                 [::]:111               [::]:*
LISTEN   0        128                 [::]:22                [::]:*
LISTEN   0        25                  [::]:514               [::]:*
[root@mr ~]#

  • 7.修改密码,使用临时密码登录

`bash
[root@mr ~]# mysql -uroot -p’-ff3uq#Fee%k’
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@mr ~]# yum whatprovides libncurses.so.5
Last metadata expiration check: 0:34:58 ago on Wed 27 Jul 2022 05:02:10 PM CST.

ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5

ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5

[root@mr ~]# dnf install -y ncurses-compat-libs
Last metadata expiration check: 0:35:39 ago on Wed 27 Jul 2022 05:02:10 PM CST.

Dependencies resolved.

===================================================================================
Package Arch Version Repository Size
===================================================================================
Installing:
ncurses-compat-libs x86_64 6.1-9.20180224.el8 baseos 328 k

Transaction Summary

Install 1 Package

Total download size: 328 k
Installed size: 1.0 M
Downloading Packages:
ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm 735 kB/s | 328 kB 00:00

Original: https://www.cnblogs.com/marymary/p/16526187.html
Author: 溜溜威
Title: mysql进阶

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/505138/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • String s = new String(“xyz”)创建了几个实例你真的能答对吗?

    从面试题说起 String s = new String("xyz"); 创建了几个实例? 这是一道很经典的面试题,在一本所谓的Java宝典上,我看到的&#82…

    数据库 2023年6月16日
    082
  • 4_Spring

    Spring的基本组成: 1、最完善的轻量级核心框架。 2、通用的事务管理抽象层。 3、JDBC抽象层。 4、集成了Toplink, Hibernate, JDO, and iBA…

    数据库 2023年6月11日
    072
  • web监听器解析

    监听器是web三大组件之一,事件监听机制如下: 事件:某个事件,如果初始化上下文 事件源:事件发生的地方 监听器:一个对象,拥有需要执行的逻辑 注册监听:将事件、事件源、监听器绑定…

    数据库 2023年6月16日
    082
  • Redis集群(二)哨兵模式

    一、作用和架构 1. 作用 Redis Sentinel,即Redis哨兵,在Redis 2.8版本开始引入。哨兵的核心功能是 主节点的自动故障转移。下面是Redis官方文档对于哨…

    数据库 2023年6月11日
    090
  • Java面试题(六)–Redis

    1 Redis基础篇 1、简单介绍一下Redis优点和缺点? 优点: 1、本质上是一个 Key-Value 类型的内存数据库,很像memcached 2、整个数据库统统加载在内存当…

    数据库 2023年6月16日
    087
  • MySQL之自关联查询

    假设要设计两张表,一张省份表(provinces),一张城市表(citys) 省份表结构 id ptitle 城市表结构 id ctitle proid(表示城市所属的省,对应着省…

    数据库 2023年5月24日
    0120
  • Tomcat配置文件Server.xml解析

    一、Sax的事件驱动模型 类图 基础实现类 DefaultHandler2: 此类扩展了SAX2基本处理程序类,以支持SAX2 LexicalHandler , DeclHandl…

    数据库 2023年6月11日
    057
  • MySQL处理Java客户端连接

    在MySQL里面往往有一个主线程,这是单线程,它不断的循环查看是否有socket是否有读写事件,如果有读写事件,再从线程池里面找个工作线程处理这个socket的读写事件,完事之后工…

    数据库 2023年6月11日
    0109
  • gitlab

    版本控制gitlab 1. 版本控制介绍 2. gitlab部署 版本控制介绍 版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思…

    数据库 2023年6月14日
    097
  • SQL语句的整合

    基础语法 https://blog.csdn.net/m0_37989980/article/details/103413942 CRUD 提供给数据库管理员的基本操作,CRUD(…

    数据库 2023年5月24日
    099
  • Java 线程是如何启动的?

    Java启动线程的代码: 根据以上代码分析,并从源码了解启动线程发生了以下事件来完成启动线程: 1、Java 创建线程和启动 2、调用本地方法 start0(); 3、JVM 中 …

    数据库 2023年6月16日
    083
  • Javaweb-Ajax详解

    一、概念 Ajax = Asynchronous JavaScript and XML(异步的JavaScript和XML) Ajax不是一种新的编程语言,而是一种用于创建更好更快…

    数据库 2023年6月16日
    079
  • 汇编debug的安装

    实验一查看CPU和内存,用机器指令和汇编指令编程 在做实验前需要debug命令。 工具:dosbox,debug.exe 安装:dosbox :https://www.dosbox…

    数据库 2023年6月11日
    0112
  • 多商户商城系统功能拆解21讲-平台端分销订单

    多商户商城系统,也称为B2B2C(BBC)平台电商模式多商家商城系统。可以快速帮助企业搭建类似拼多多/京东/天猫/淘宝的综合商城。 多商户商城系统支持商家入驻加盟,同时满足平台自营…

    数据库 2023年6月14日
    0101
  • Element UI的第一个程序(标签使用)

    1:Element UI 官方文档:https://element.faas.ele.me/ 2:Element UI是什么? 网站快速成型工具 *Element,一套为开发者、设…

    数据库 2023年6月6日
    099
  • Struts 2 学习笔记

    Struts2 是一个基于 MVC 设计模式的 Web 应用框架,它本质上相当于一个 servlet,在 MVC 设计模式中,Struts2 作为控制器(Controller)来建…

    数据库 2023年6月11日
    087
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球