MySQL的简介和安装

MySQL数据库简介


数据库网站排行(所有热门数据库都有):https://db-engines.com/en/

使用虚拟机软件:VMware Fusion

一、数据库(初始化)版本变化:

1、5.6——mysql_install_db

2、5.7——mysqld --initialize-insecure

二、密码策略:

策略 检查规则
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

1、如果是rpm包安装则是medium密码强度,一般是12位密码长度,180天密码过期,以上3种密码复杂度

2、密码的字段为:authentication_strings需要在免密情况下使用

三、MySQL安装方法

1、二进制包安装
二进制格式的包名字很长,都带有版本号、适应平台、适应的硬件类型等比如mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz这样的是二进制包,还会有可执行文件,会有bin目录。

2、源码包安装
源码格式仅仅就是一个版本号的tar包,比如mysql-5.0.45.tar.gz 是 源码包,会有源代码文件,没有bin目录,需要make,make install编译。

3、yum源安装
直接安装即可

[root@hdfeng ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@hdfeng ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@hdfeng ~]# yum -y install mysql-community-server

四、版本选择

有三种版本可以选择,分别是:
1、oracle:mysql官方版5.6 5.7稳定版本 GA稳定发布 版本(经典版本5.7.20)

2、redhat:mariaDB

3、percona:perconaDB

五、NoSQL和RDBMS的区别

NoSQL:非关系型数据库管理系统适合于高性能存储数据,一般配合RDBMS进行使用,针对大数据处理分析,分布式框架更加擅长。
NoSQL数据库:Hbase 键-值(key-value):Redis、memcached document:Mongodb

RDBMS:关系型数据库管理系统,处理关系复杂的数据以及重要性比较高的存储
RDBMS数据库:MySQL、Oracle、SQLserver、PG

MySQL数据库安装

一、安装方式

这里的话讲解的是二进制tar的安装使用,可直接wget到linux或者复制地址下载即可。

[root@hdfeng ~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

二、开始安装(按1,2,3的步骤下去即可)

1、在环境变量里面加:

[root@hdfeng ~]# vim /etc/profile
export PATH=/opt/app/mysql/bin:$PATH
[root@hdfeng ~]# source /etc/profile  使环境变量生效

2、环境目录:
mysql服务:/opt/mysql
mysql数据文件:/opt/mysql-data
分别给两个文件夹下的文件授权:

[root@hdfeng ~]# chown -R mysql.mysql /opt/mysql/*
[root@hdfeng ~]# chown -R mysql.mysql /opt/mysql-data/*

3、进行建库操作(选以下之一初始化数据库即可):

[root@hdfeng ~]# mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql-data 有密码

[root@hdfeng ~]# mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql-data 初始化数据,无密码

4、修改配置文件:

[root@hdfeng ~]# vim /etc/my.cnf
[mysqld]
user=mysql       			用户名
basedir=/opt/mysql    		程序路径
datadir=/opt/mysql-data 	程序数据路径
server_id=6			    	必加(不同其它数据库的一个值)
port=3306			    	端口号
socket=/tmp/mysql.sock  	socket初始化配置参数
[mysql]
socket=/tmp/mysql.sock      可以注释,默认就是去这个配置文件
prompt=mysql [\\d]>

5、配置完成启动关闭(看看是否能启动,如果启动不了检查配置文件以及mysql-data目录是否初始化成功):

[root@hdfeng ~]# cd /opt/mysql/support-files/
./mysql.server start 
./mysql.server stop

启动查看方式(三种都可以查看):

[root@hdfeng ~]# ps -ef | grep mysqld
[root@hdfeng ~]# ss -nlp | grep 3306
[root@hdfeng ~]# netstat -nlp | grep 3306

便捷启动方式(也可以不配):

6、使用service方式(如果需要可以配置):

[root@hdfeng ~]# cp /opt/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@hdfeng ~]# service mysqld start
[root@hdfeng ~]# service mysqld status
[root@hdfeng ~]# service mysqld stop
[root@hdfeng ~]# service mysqld restart

7、使用systemctl方式(如果需要可以配置):
使用systemctl restart/start/stop/status mysqld需要以下配置:

需要修改ExecStart路径到自己mysql二进制包的路径下即可
[root@hdfeng ~]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000

8、然后开启数据库服务以后就可以开始操作了
mysql命令直接进入mysql数据库

[root@hdfeng ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 [(none)]>

9、如需要设置密码则:

[root@hdfeng ~]# mysqladmin -u root -p password
Enter password:					因为之前是空密码,这里直接回车即可
New password:					新密码自己输入即可,初始化没有密码策略
Confirm new password:			再次输入密码
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

10、如果需要查看mysql用户名密码:

mysql [(none)]>select user,host,authentication_string from mysql.user;
 --------------- ----------- ------------------------------------------- 
| user          | host      | authentication_string                     |
 --------------- ----------- ------------------------------------------- 
| root          | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root          | %         | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
 --------------- ----------- ------------------------------------------- 
4 rows in set (0.00 sec)
mysql [(none)]>desc mysql.user; 
还可查看表结构,按照需要的字段进行查询
发布了3 篇原创文章 · 获赞 1 · 访问量 420

猜你喜欢

转载自blog.csdn.net/fhdsece/article/details/104190395