数据库简介

2022/3/1 19:51:39

本文主要是介绍数据库简介,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、数据库简介

张三 123
李四 456

关系型数据库

2、yum安装数据库

1、卸载残留
[root@localhost ~]# yum remove mariadb* -y

2、下载yum源
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm

3、安装yum源
[root@localhost ~]# yum install mysql80-community-release-el7-5.noarch.rpm -y

4、查看仓库
[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                 230
mysql-tools-community/x86_64      MySQL Tools Community                      138
mysql80-community/x86_64          MySQL 8.0 Community Server                 321

5、更换5.7版本的yum源
[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yum-config-manager --disable mysql80-community
[root@localhost ~]# yum-config-manager --enable mysql57-community

6、安装MySQL 
[root@localhost ~]# yum install -y  mysql-community-server

7、启动MySQL
[root@localhost ~]# systemctl start mysqld

8、获取默认密码
[root@localhost ~]# cat /var/log/mysqld.log | grep password
2022-02-25T10:21:47.132735Z 1 [Note] A temporary password is generated for root@localhost: pdHs8fc.ss-o

9、登录
[root@localhost ~]# mysql -uroot -p'pdHs8fc.ss-o'

10、修改数据库默认密码
mysql> alter user root@localhost identified by 'Test123!';
mysql> exit

3、二进制安装数据库

1、清除残留
[root@localhost ~]# yum remove mariadb* -y

2、下载安装包

image-20220225103943897

image-20220225104007111

image-20220225104204373

image-20220225104304074

image-20220225104331952

image-20220225104616257

3、安装
[root@localhost ~]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ln -s /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.37

4、统一用户
[root@localhost mysql-5.7.37]# groupadd mysql -g 666
[root@localhost mysql-5.7.37]# useradd mysql -g 666 -u 666 -r -M -s /sbin/nologin

5、创建配置文件
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
# 安装目录
basedir=/usr/local/mysql-5.7.37
# 存放数据的目录
datadir=/usr/local/mysql-5.7.37/data
# 指定端口号
port=3306
# 指定Socket文件存放路径
socket=/usr/local/mysql-5.7.37/data/mysql.sock
# 指定默认的字符集编码
character-set-server=utf8
# MySQL错误日志路径
log-error=/var/log/mysqld.log
# 指定MySQL pid文件路径
pid-file=/usr/local/mysql-5.7.37/data/mysqld.pid
[mysql]
socket=/usr/local/mysql-5.7.37/data/mysql.sock
[client]
socket=/usr/local/mysql-5.7.37/data/mysql.sock

6、创建数据目录
[root@localhost run]# mkdir /usr/local/mysql-5.7.37/data

7、授权
[root@localhost ~]# chown mysql.mysql -R /usr/local/mysql-5.7.37
[root@localhost ~]# chown mysql.mysql -R /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/
[root@localhost ~]# touch /var/log/mysqld.log
[root@localhost ~]# chown -R mysql.mysql /var/log/mysqld.log

8、安装MySQL依赖软件
[root@localhost ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ numactl libaio glibc cmake autoconf

9、初始化数据库
[root@localhost mysql-5.7.37]# pwd
/usr/local/mysql-5.7.37
[root@localhost mysql-5.7.37]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.37 --datadir=/usr/local/mysql-5.7.37/data

10、注册MySQL启动服务
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/usr/local/mysql-5.7.37/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start mysqld

11、测试连接
[root@localhost data]# cat /var/log/mysqld.log | grep password
2022-02-25T10:57:13.801643Z 1 [Note] A temporary password is generated for root@localhost: fjrP<Tas.1iD
[root@localhost data]# /usr/local/mysql-5.7.37/bin/mysql -uroot -p'fjrP<Tas.1iD'

12、修改默认密码
mysql> alter user root@localhost identified by 'Test123!';
Query OK, 0 rows affected (0.00 sec)

13、添加环境变量
[root@localhost data]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql-5.7.37
export PATH=$PATH:$MYSQL_HOME/bin
[root@localhost data]# source /etc/profile

4、以源码的方式部署MySQL

1、下载MySQL数据库源代码

image-20220225113712013

2、解压

[root@localhost ~]# tar -xf mysql-5.7.36.tar.gz 
# 安装boots
[root@localhost ~]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

3、统一用户

[root@localhost mysql-5.7.37]# groupadd mysql -g 666
[root@localhost mysql-5.7.37]# useradd mysql -g 666 -u 666 -r -M -s /sbin/nologin

4、配置文件

[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
# 安装目录
basedir=/usr/local/mysql-5.7.36
# 存放数据的目录
datadir=/usr/local/mysql-5.7.36/data
# 指定端口号
port=3306
# 指定Socket文件存放路径
socket=/usr/local/mysql-5.7.36/data/mysql.sock
# 指定默认的字符集编码
character-set-server=utf8
# MySQL错误日志路径
log-error=/var/log/mysqld.log
# 指定MySQL pid文件路径
pid-file=/usr/local/mysql-5.7.36/data/mysqld.pid
[mysql]
socket=/usr/local/mysql-5.7.36/data/mysql.sock
[client]
socket=/usr/local/mysql-5.7.36/data/mysql.sock

5、安装依赖软件

[root@localhost mysql-5.7.36]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel

6、安装Boot

[root@localhost ~]#  tar -xf boost_1_59_0.tar.gz -C /usr/local/

7、创建数据目录

[root@localhost ~]# mkdir /usr/local/mysql-5.7.36
[root@localhost ~]# chown mysql.mysql -R /usr/local/mysql-5.7.36

8、设置编译参数

[root@localhost mysql-5.7.36]# pwd
/root/mysql-5.7.36

[root@localhost mysql-5.7.36]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.36 \
-DMYSQL_DATADIR=/usr/local/mysql-5.7.36/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.36/tmp/mysql.sock \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0

# 编译
[root@localhost mysql-5.7.34]# make

# 安装
[root@localhost mysql-5.7.34]# make install

# 创建数据目录
[root@localhost ~]# mkdir /usr/local/mysql-5.7.36/data

# 统一用户
[root@localhost mysql-5.7.36]# chown mysql.mysql -R /usr/local/mysql-5.7.36

9、初始化

[root@localhost mysql-5.7.36]# touch /var/log/mysqld.log
[root@localhost mysql-5.7.36]# chown mysql.mysql /var/log/mysqld.log
[root@localhost mysql-5.7.36]# cd /usr/local/mysql-5.7.36
[root@localhost mysql-5.7.36]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.36/ --datadir=/usr/local/mysql-5.7.36/data/

10、注册MySQL服务

[root@localhost mysql-5.7.36]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/usr/local/mysql-5.7.36/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

[root@localhost mysql-5.7.36]# systemctl daemon-reload
[root@localhost mysql-5.7.36]# systemctl start mysqld

11、连接并修改密码

[root@localhost mysql-5.7.36]# 
[root@localhost mysql-5.7.36]# cat /var/log/mysqld.log | grep password
2022-02-25T07:18:46.118864Z 1 [Note] A temporary password is generated for root@localhost: yNvvis<gw0N&
[root@localhost mysql-5.7.36]# /usr/local/mysql-5.7.36/bin/mysql -uroot -p'localhost'
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.36

Copyright (c) 2000, 2021, 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> alter user root@localhost identified by 'Test123!';
Query OK, 0 rows affected (0.00 sec)


这篇关于数据库简介的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程