MySQL学习笔记3

news2024/10/5 16:21:14

MySQL的源码编译安装:

1、参考MySQL的源码安装官方文档:

2、源码安装定制选项:

3、源码安装三部曲:配置、编译、安装。

4、软件安装包:

mysql-boost-5.7.43.tar.gz

5、安装需求:

安装需求具体配置
安装目录basedir/mysql_3307
数据目录datadir/mysql_3307/data
端口号3307
socket文件位置$basedir/mysql.sock
字符集utf8mb4

主要安装目录、端口和socket套接字不一样,就可以在一台服务器上安装两个mysql。

6、了解配置选项:

源码安装,可定制性比较强。 

其中collation:

 核对、校验的意思。

ENABLED_LOCAL_INFILE:外部数据,导入的时候,需要开启该功能。

 

安装步骤:

1)安装依赖包:

[root@mysql-server ~]# yum -y install ncurses-devel cmake libaio-devel openssl-devel

 2)上传mysql源码包,并解压:

这个时候做一个拍照。

[root@mysql-server ~]# tar -zxvf mysql-boost-5.7.43.tar.gz

3)进入到解压目录里配置:

[root@mysql-server ~]# cd mysql-5.7.43

4)编写脚本进行配置 vim myconfig.sh:

cmake . \
-DCMAKE_INSTALL_PREFIX=/mysql_3307 \
-DMYSQL_DATADIR=/mysql_3307/data \
-DMYSQL_TCP_PORT=3307 \
-DMYSQL_UNIX_ADDR=/mysql_3307/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_SSL=system \
-DWITH_BOOST=/mysql_3307/boost \
-DDOWNLOAD_BOOST=1

说明:在这个配置里,如果还需要安装别的数据库,只要修改几个地方:

 -DCMAKE_INSTALL_PREFIX

-DMYSQL_DATADIR

-DMYSQL_TCP_PORT

-DMYSQL_UNIX_ADDR

5)添加脚本执行权限,然后执行脚本。

[root@mysql-server mysql-5.7.43]# chmod +x mysqlconfig.sh
[root@mysql-server mysql-5.7.43]# ./mysqlconfig.sh

这个过程是一个配置的过程。 

6)编译和安装:

make && make install

 也可以写成:

make -j2 && make install

选项:

-j2:代表同时开启多个线程共同实现编译操作。

MySQL数据库的初始化工作:

1)进入到/mysql_3307

[root@mysql-server mysql-5.7.43]# cd /mysql_3307
[root@mysql-server mysql_3307]# pwd
/mysql_3307

2)创建mysql-files目录:

[root@mysql-server mysql_3307]# mkdir mysql-files
[root@mysql-server mysql_3307]# chown mysql:mysql mysql-files
[root@mysql-server mysql_3307]# chmod 750 mysql-files

3)初始化数据库:

[root@mysql-server mysql_3307]# bin/mysqld --initialize --user=mysql --basedir=/mysql_3307 --datadir=/mysql_3307/data
2023-09-22T16:03:38.325762Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-09-22T16:03:38.507868Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-09-22T16:03:38.532672Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-09-22T16:03:38.586904Z 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: 97a3f645-5961-11ee-8c2b-000c295cf01e.
2023-09-22T16:03:38.587416Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-09-22T16:03:38.703329Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-09-22T16:03:38.703383Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-09-22T16:03:38.703732Z 0 [Warning] CA certificate ca.pem is self signed.
2023-09-22T16:03:38.736069Z 1 [Note] A temporary password is generated for root@localhost: _uhi%b?us9Qr

里面创建了data目录,data目录里面有mysql目录。

4)启动数据库:

[root@mysql-server mysql_3307]# cp support-files/mysql.server /etc/init.d/mysql_3307
[root@mysql-server mysql_3307]# service mysql_3307 start

常见启动异常的解决方案:

 查看日志:

解决办法:很多问题跟权限有关,要理解权限、拥有者、所属组。

[root@mysql-server /]# chown -R mysql:mysql mysql_3307

也可以使用chmod命令更改权限,如果该了权限,可能不符合权限最小化的原则

安装完后续配置:

[root@mysql-server mysql_3307]# cat my.cnf
[mysqld]
basedir=/mysql_3307
datadir=/mysql_3307/data
socket=/mysql_3307/mysql.sock


[root@mysql-server mysql_3307]# service mysql_3307 restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

别忘了要将mysql_3307重启。

设置数据库管理root的密码:

bin/mysqladmin -uroot password '1q2w3e4r' -p

安全设置:

[root@mysql-server mysql_3307]# bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

添加mysql_3307的开机启动项:

[root@mysql-server ~]# chkconfig --add mysql_3307
[root@mysql-server ~]# chkconfig mysql_3307 on
[root@mysql-server ~]#
[root@mysql-server ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql_3306      0:off   1:off   2:on    3:on    4:on    5:on    6:off
mysql_3307      0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

mysql常见问题解决方案:

1、如何访问不同的数据库?

方法一:直接使用==对应的客户==端软件访问:

访问5.7.31版本数据库:
[root@node1 ~]# /mysql_3306/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)

访问5.7.31版本数据库:
[root@node1 ~]# /mysql_3307/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.31 Source distribution

方法二:==定义别名==的方式访问

[root@node1 ~]# alias mysql_3306="/mysql_3306/bin/mysql"
[root@node1 ~]# alias mysql_3307="/mysql_3307/bin/mysql"
[root@node1 ~]# mysql_3306 -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.31 MySQL Community Server (GPL)

[root@node1 ~]# mysql_3307 -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.31 Source distribution

方法三:==拷贝相应命令==到PATH可以识别的路径下==并重命名==

[root@node1 ~]# unalias mysql_3306
[root@node1 ~]# unalias mysql_3307
+++++++++++++++++++++我是华丽分隔符+++++++++++++++++++++++++++
[root@node1 ~]# cp /mysql_3306/bin/mysql /usr/bin/mysql_3306
[root@node1 ~]# cp /mysql_3307/bin/mysql /usr/bin/mysql_3307
[root@node1 ~]# which mysql_3306
/usr/bin/mysql_3306
[root@node1 ~]# which mysql_3307
/usr/bin/mysql_3307

我个人感觉还是倾向于第三种方法。

思考:我们之所以能够连接到数据库服务器的本质,就是套接字。

MySQL密码忘记了如何解决:

这个需要按照老师的步骤进行下联系。

[root@mysql-server ~]# ps aux |grep mysql
root        934  0.0  0.0 115544  1708 ?        S    13:08   0:00 /bin/sh /mysql_3307/bin/mysqld_safe --datadir=/mysql_3307/data --pid-file=/mysql_3307/data/mysql-server.lnmp.com.pid
mysql      1213  0.1  9.0 1144064 183968 ?      Sl   13:08   0:00 /mysql_3307/bin/mysqld --basedir=/mysql_3307 --datadir=/mysql_3307/data --plugin-dir=/mysql_3307/lib/plugin --user=mysql --log-error=mysql-server.lnmp.com.err --pid-file=/mysql_3307/data/mysql-server.lnmp.com.pid --socket=/mysql_3307/mysql.sock
root       1621  0.0  0.0  11824  1592 pts/0    S    13:13   0:00 /bin/sh /mysql_3306/bin/mysqld_safe --datadir=/mysql_3306/data --pid-file=/mysql_3306/data/mysql-server.lnmp.com.pid
mysql      1750  0.2  8.9 1121060 180816 pts/0  Sl   13:13   0:00 /mysql_3306/bin/mysqld --basedir=/mysql_3306 --datadir=/mysql_3306/data --plugin-dir=/mysql_3306/lib/plugin --user=mysql --log-error=mysql-server.lnmp.com.err --pid-file=/mysql_3306/data/mysql-server.lnmp.com.pid --socket=/tmp/mysql.sock
root       1887  0.0  0.0 112812   972 pts/0    S+   13:14   0:00 grep --color=auto mysql
[root@mysql-server ~]# service mysql_3306 restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@mysql-server ~]# service mysql_3307 restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

mysqladmin工具的使用:

关闭数据库
[root@node1 ~]# mysqladmin shutdown -p
默认修改数据库管理员root密码
[root@node1 ~]# mysqladmin password 'newpass' -p
[root@node1 ~]# mysqladmin password '123' -uroot -h localhost -p

查看扩展信息,比如变量
[root@node1 ~]# mysqladmin proc extended-status -p
创建数据库
[root@node1 ~]# mysqladmin create db01 -p
删除数据库
[root@node1 ~]# mysqladmin drop db01 -p

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1034296.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

安装gpu版本的paddle和paddleclas

安装gpu版本的paddle python -m pip install paddlepaddle-gpu2.3.2.post111 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html以上支持cuda11.1版本 其他需求可查阅文档在这里 安装paddleclas 1 在虚拟环境中安装所需的Python库: pip inst…

Cortex-M3/M4堆栈

一、Cortex-M3/M4堆栈操作 Cortex-M3/M4 使用的是“向下生长的满栈”模型。堆栈指针 SP 指向最后一个被压入堆栈的 32 位数值。在下一次压栈时, SP 先自减 4, 再存入新的数值,如图所示为堆栈的PUSH操作。 POP 操作刚好相反:先从 …

电子信息工程专业课复习知识点总结:(五)通信原理

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 第一章通信系统概述——通信系统的构成、各部分性质、性能指标1.通信系统的组成?2.通信系统的分类?3.调制、解调是什么?有什么用…

MySQL详解六:备份与恢复

文章目录 1. 数据库备份的分类1.1 从物理和逻辑上分类1.1.1 物理备份1.1.2 逻辑备份 1.2 从数据库的备份策略角度上分类1.2.1 完全备份1.2.2 差异备份1.2.3 增量备份 1.3 常见的备份方法 2. MySQL完全备份2.1 完全备份简介2.2 优点与缺点2.3 实现物理冷备份与恢复2.3.1 实现流程…

备受以太坊基金会青睐的 Hexlink,构建亿级用户涌入 Web3的入口

早在2021年9月,以太坊创始人Vitalik Buterin就曾提出了EIP-4337(账户抽象)提案,并在去年10月对该提案进一步更新,引发行业的进一步关注。在今年3月,EIP-4337提案正式通过审计,并成为了ERC-4337标…

conda常用指令

常用conda指令 查看当前有哪些环境,有base环境 conda env list 创建环境 # conda create -n 你的环境名 python版本号 # 创建python3.10,名为env虚拟环境 conda create -n env python3.10 激活环境 conda activate env

java框架-Spring-AOP

AOP:动态代理 开发步骤: 导入aop模块定义业务逻辑类定义切面类; -. 切面类标注:Aspect -. 切面类注解: Before: 前置通知, 在方法执行之前执行 After: 后置通知, 在方法执行之后执行 。 AfterRunning: 返回通知, 在方法返回结果之…

[杂谈]-快速了解半波和全波整流

快速了解半波和全波整流 文章目录 快速了解半波和全波整流1、滤波2、半波整流器3、全波整流器4、常见问题 整流器是一种将交流信号转换为脉动直流信号以及将交流电转换为直流电的电子电路。 我们日常生活中几乎所有的电子项目都会用到它。 根据周期传导,本文我们介绍…

【Python】ModuleNotFoundError: No module named ‘Crypto‘

今天在使用一个新的库Crypto时发生了报错 Crypto安装成功~ 导入Crypto模块也没有问题 运行时却发生了报错: 没有这个模块? 我明明安装成功了,为什么报错没有这个库呢? 于是我去查看了一下是不是没有安装上呢? 为什么…

sql注入挖掘

出现的条件 只要是和数据库有交互 没有过滤拼接的sql语句可以执行 判断 这个是在url筐里的

想要精通算法和SQL的成长之路 - 双指针【数组】

想要精通算法和SQL的成长之路 - 双指针【数组】 前言一. 合并两个有序数组二. 删除有序数组中的重复项 II 前言 想要精通算法和SQL的成长之路 - 系列导航 一. 合并两个有序数组 原题链接 抓住重点信息: 两个数组都是非递减顺序排列。num1数组,末尾包…

在Bat To Exe Converter,修改为当异常结束或终止时,程序重新启动执行

在Bat To Exe Converter,修改为当异常结束或终止时,程序重新启动执行 .bat中的代码部分: .bat中的代码echo offpython E:\python\yoloProjectTestSmallLarge\detect.pypause,我想你能帮在Bat To Exe Converter,修改成…

JAVA入坑之嵌套类

一、嵌套类入门 1.1概述 Java嵌套类是指在一个类中定义另一个类的一种方式,它可以提高代码的可读性、可维护性和封装性。Java嵌套类分为两种类型:静态嵌套类和非静态嵌套类。 静态嵌套类:Static nested classes,即类前面有static修饰符 非静…

【进阶C语言】字符串与内存库函数认识与模拟实现

本章内容大致目录: 1.strlen函数 2.strcpy函数 3.strcmp函数 4.strcat函数 5.strstr函数 6.strtok函数 7.strerror与perror函数 8.字符操作函数 9.内存操作函数 10.总结 以上函数均属于库函数,有的函数则会介绍如何模拟实现。 一、strlen函数…

conda创建虚拟环境安装aix360

目录 创建虚拟环境查看已有虚拟环境进入所创建的虚拟环境查看已安装的程序查看已安装的python模块配置镜像pipconda 安装aix360将环境添加到jupyter删除虚拟环境 创建虚拟环境 建议装python3.7python3.7python3.7python3.7python3.7python3.7python3.7python3.7python3.7pytho…

YTM32的LIN通信协议引擎LinFlexD外设模块详解

YTM32的LIN通信协议引擎LinFlexD外设模块详解 文章目录 YTM32的LIN通信协议引擎LinFlexD外设模块详解LINFlexD外设简介LINFlexD工作机制初始化主机模式从机模式错误状态标志位超时错误(Timeout Error)ID过滤机制接收器检测帧间隔段和帧间隔段分隔符产生波…

[游戏开发][Shader]GLSLSandBox转Unity-CG语言

官网 GLSL Sandbox Galleryhttps://glslsandbox.com/ 屏幕坐标计算 fragCoord与_ScreenParams mat2矩阵转换 vec2向量 在GLSL里mat2(a, b, c, d)函数返回vec2但是在CG语言里 没有mat2函数,用下面的值替换mat2方法vec2(a * 1. c * 1., b * 1. d * 1.);举例&…

一台电脑远程内网的另外一台电脑,禁止远程的电脑连接外网,只允许内网连接

一台电脑远程内网的另外一台电脑,禁止远程的电脑连接外网,只允许内网连接 1.找到右下角网卡图标,右键图标选择“打开网络和共享中心”。 3、点击“更改适配器设置”。 4、右键正在使用的网卡“本地连接”打开属性 5、找到“internet协…

vue简单案例----小张记事本

小张记事本 具体效果如图所示&#xff0c;这里就简单展示&#xff0c;还有很多不足的地方&#xff0c;希望大家可以对这个小项目进行改进&#xff0c;话不多说可以参考下面的代码 源代码如下 <html lang"en"><head><meta charset"UTF-8"…

1786_MTALAB代码生成把通用函数生成独立文件

全部学习汇总&#xff1a; GitHub - GreyZhang/g_matlab: MATLAB once used to be my daily tool. After many years when I go back and read my old learning notes I felt maybe I still need it in the future. So, start this repo to keep some of my old learning notes…