Mysql 数据库系统部署使用

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

一、部署 Mysql 数据库系统

1、配置 yum 仓库安装依赖软件

1) 挂载系统盘

Mysql 数据库系统部署使用_数据库

2)挂载系统光盘到/mnt 目录

[root@centos01 ~]# mount /dev/cdrom /mnt/
lmount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7
TRANS.TBL

Mysql 数据库系统部署使用_centos_02

3)删除系统自带 yum 仓库配置本地 yum 仓库

[root@centos01 ~]# rm -rf /etc/yum.repos.d/Centos-*
[root@centos01 ~]# ls /etc/yum.repos.d/local.repo
[root@centos01 ~]# vim /etc/yum.repos.d/local.repo
[local]
name=centos7
baseurl=file:///mnt
enabled=1
gpgcheck=0

Mysql 数据库系统部署使用_mysql_03

Mysql 数据库系统部署使用_centos_04

4)安装依赖程序

[root@centos01 ~]# yum -y install ncurses-devel cmake

Mysql 数据库系统部署使用_mysql_05

2、切换 mysql 程序光盘解压源代码程序

1)卸载系统光盘挂载点

[root@centos01 ~]# umount /mnt/
[root@centos01 ~]# ls /mnt/

Mysql 数据库系统部署使用_mysql_06

2) 切换 mysql 程序光盘

Mysql 数据库系统部署使用_数据库_07

3)挂载 mysql 程序光盘

[root@centos01 ~]# mount /dev/cdrom /mnt/ 
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# ls -ld /mnt/mysql-5.5.22.tar.gz
-r-xr-xr-x 1 root root 24475686 6 月 26 2014 /mnt/mysql-5.5.22.tar.gz

Mysql 数据库系统部署使用_数据库_08

4)解压源代码程序到/usr/src 目录

[root@centos01 ~]# tar zxvf /mnt/mysql-5.5.22.tar.gz -C /usr/src/
[root@centos01 ~]# ls /usr/src/
debug kernels mysql-5.5.22

Mysql 数据库系统部署使用_数据库_09

3、配置安装 mysql

1)配置 mysql

[root@centos01 ~]# cd /usr/src/mysql-5.5.22/cmake \ //使用 cmake 工具配置mysql
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //指定安装位置
-DSYSCONFDIR=/etc \ //初始化参数
-DDEFAULT_CHARSET=utf8 \ //默认字符编码 utf8
-DDEFAULT_COLLATION=utf8_general_ci \ //校验字符编码
-DWITH_EXTRA_CHARSETS=all //支持更多字符编码

Mysql 数据库系统部署使用_centos_10

2)编译安装 mysql

[root@centos01 mysql-5.5.22]# make && make install
[root@centos01 mysql-5.5.22]# ls -ld /usr/local/mysql/
drwxr-xr-x 13 root root 213 7 月 25 18:33 /usr/local/mysql/

Mysql 数据库系统部署使用_mysql_11

Mysql 数据库系统部署使用_mysql_12

3)创建管理 mysql 组和用户

[root@centos01 mysql-5.5.22]# groupadd mysql
[root@centos01 mysql-5.5.22]# useradd -M -s /sbin/nologin mysql -g mysql

Mysql 数据库系统部署使用_数据库_13

4)修改目录的所有者

[root@centos01 mysql-5.5.22]# chown -R mysql:mysql /usr/local/mysql/
[root@centos01 mysql-5.5.22]# ls -ld /usr/local/mysql/
drwxr-xr-x 13 mysql mysql 213 7 月 25 18:33 /usr/local/mysql/

Mysql 数据库系统部署使用_数据库_14

5)生成 mysql 主配置文件覆盖原有文件

[root@centos01 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y

Mysql 数据库系统部署使用_mysql_15

6)生成服务添加执行权限添加为系统服务设置开机自动启动

[root@centos01 mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos01 mysql-5.5.22]# chmod +x /etc/init.d/mysqld
[root@centos01 mysql-5.5.22]# chkconfig --add mysqld
[root@centos01 mysql-5.5.22]# chkconfig --level 35 mysqld on

Mysql 数据库系统部署使用_centos_16

7)优化 mysql 执行命令

[root@centos01 mysql-5.5.22]# vim /etc/profile# /etc/profile
PATH=$PATH:/usr/local/mysql/bin/
[root@centos01 mysql-5.5.22]# source /etc/profile

Mysql 数据库系统部署使用_数据库_17

4、控制 mysql 服务 mysql 数据库设置密码

1)启动 mysql 服务

[root@centos01 ~]# systemctl start mysqld
[root@centos01 ~]# netstat -anptu | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
11581/mysqld

Mysql 数据库系统部署使用_mysql_18

2)空密码登录 mysql 数据库和退出

[root@centos01 ~]# mysql -uroot -p
Enter password:
mysql> exit
Bye

Mysql 数据库系统部署使用_数据库_19

3)设置 mysql 密码使用账户密码管理登录

[root@centos01 ~]# mysql -uroot -ppwd@123

Mysql 数据库系统部署使用_centos_20

二、mysql 数据库表和记录管理

​1、数据库管理

1)登录 mysql 创建数据库名字 HB3035

[root@centos01 ~]# mysql -uroot -ppwd@123
mysql> create database HB3035;
Query OK, 1 row affected (0.00 sec)

Mysql 数据库系统部署使用_centos_21

2)查看创建的数据库

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| HB3035 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)

Mysql 数据库系统部署使用_mysql_22

3)切换到创建的 HB3035 数据库和 mysql 数据库

mysql> use HB3035;Database changed
mysql> use mysql;
Database changed

Mysql 数据库系统部署使用_centos_23

4)删除 HB3035 数据库查看创建的数据库

mysql> drop database HB3035;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

Mysql 数据库系统部署使用_centos_24

2、数据库表的管理

1)创建 accp 数据库,在 accp 数据库创建 student 表,设置表格 4 列数据三类为字符串 1

列数据为整数类

mysql> create database accp;
Query OK, 1 row affected (0.00 sec)
mysql> create table accp.student (姓名 char(4),年龄 init,电话 char(11),身份证号码
char(18),primary key(身份证号码));

2)查看创建的表结构

mysql> desc accp.1;
+-----------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+----------+------+-----+---------+-------+
| 姓名 | char(4) | YES | | NULL | |
| 年龄 | int(11) | YES | | NULL | |
| 电话 | char(11) | YES | | NULL | |
| 身份证号码 | char(18) | NO | PRI | | |
+-----------------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

Mysql 数据库系统部署使用_数据库_25

3)切换到 accp 数据库,查看创建的表

mysql> use accp;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_accp |
+-----------------+
| student |
+-----------------+
2 rows in set (0.00 sec)

4)删除创建的 1 表

mysql> drop table 1
Query OK, 0 rows affected (0.01 sec)

3、表中记录管理

1)1表中插入连续列数据

mysql> insert into accp.student values ('xxx
',18,'13161295986','111345679124689018');
Query OK, 1 row affected (0.01 sec)

2)1表中插入不连续列数据

mysql> insert into accp.1 (姓名,身份证号码) values ('xx
','110678654108765416');
Query OK, 1 row affected (0.01 sec)

3)查看 1 表中所有数据

mysql> select * from accp.1;
+-----------+--------+-------------+--------------------+
| 姓名 | 年龄 | 电话 | 身份证号码 |
+-----------+--------+-------------+--------------------+
| xx | NULL | NULL | 110678654108765416 |
| xxx | 18 | 13161295986 | 111345679124689018 |
+-----------+--------+-------------+--------------------+
2 rows in set (0.00 sec)

4)查看 1 表的姓名和身份号码列数据

mysql> select 姓名,身份证号码 from accp.1;
+-----------+--------------------+
| 姓名 | 身份证号码 |
+-----------+--------------------+
| xx | 110678654108765416 || xxx | 111345679124689018 |
+-----------+--------------------+
2 rows in set (0.00 sec)

5)修改 stdeunt 表中数据给胡炎添加年龄和电话

mysql> update accp.student set 电话='15810350733',年龄=21 where 姓名='xx';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

6)查看修改的数据

mysql> select * from accp.1;
+-----------+--------+-------------+--------------------+
| 姓名 | 年龄 | 电话 | 身份证号码 |
+-----------+--------+-------------+--------------------+
| xx | 21 | 15810350733 | 110678654108765416 |
| xxx | 18 | 13161295986 | 111345679124689018 |
+-----------+--------+-------------+--------------------+
2 rows in set (0.00 sec)

7)查看姓名是xx的数据

mysql> select 姓名,身份证号码 from accp.student where 姓名='xx';
+--------+--------------------+
| 姓名 | 身份证号码 |
+--------+--------------------+
| xx | 110678654108765416 |
+--------+--------------------+
1 row in set (0.00 sec)

8)删除 accp 数据库的 1 中记录名字是xx的记录

mysql> select * from accp.1;
+-----------+--------+-------------+--------------------+
| 姓名 | 年龄 | 电话 | 身份证号码 |
+-----------+--------+-------------+--------------------+
| xx | 21 | 15810350733 | 110678654108765416 |
| xxx | 18 | 13161295986 | 111345679124689018 |
+-----------+--------+-------------+--------------------+
2 rows in set (0.00 sec)
mysql> delete from accp.1 where 姓名='xx';
Query OK, 1 row affected (0.01 sec)
mysql> select * from accp.1;
+-----------+--------+-------------+--------------------+
| 姓名 | 年龄 | 电话 | 身份证号码 |
+-----------+--------+-------------+--------------------+
| xxx | 18 | 13161295986 | 111345679124689018 |
+-----------+--------+-------------+--------------------+
row in set (0.00 sec)

三、授权用户管理数据和远程管理数据库修改数据库密码

1、授权和撤销授权的配置

1)授权用户 bob 对 accp 数据库下的所有表拥有完全控制权限通过远程计算机

192.168.100.20 访问

mysql> grant all on accp.* to 'bob'@'192.168.100.20' identified by 'pwd@123';
Query OK, 0 rows affected (0.00 sec)


2)查看授权的 bob 用户权限

mysql> show grants for bob@192.168.100.20;
+-----------------------------------------------------------------------------------------------------------------+
| Grants for bob@192.168.100.20 |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bob'@'192.168.100.20' IDENTIFIED BY PASSWORD '*760F60073FD235571A5260444301DB22136ED604' |
| GRANT ALL PRIVILEGES ON `accp`.* TO 'bob'@'192.168.100.20' |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

Mysql 数据库系统部署使用_mysql_26

3)撤销授权

mysql> revoke all on accp.* from 'bob'@'192.168.100.20';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for bob@192.168.100.20;
+-----------------------------------------------------------------------------------------------------------------+| Grants for bob@192.168.100.20 |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bob'@'192.168.100.20' IDENTIFIED BY PASSWORD '*760F60073FD235571A5260444301DB22136ED604' |
+-----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>

Mysql 数据库系统部署使用_mysql_27

2、授权远程 Linux 的客户端访问 mysql 数据库

1)挂载 Linux 系统光盘

[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPMGPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7
TRANS.TBL

Mysql 数据库系统部署使用_mysql_28

2)配置 yum 仓库

[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-*
[root@centos02 ~]# ls /etc/yum.repos.d/
local.repo
[root@centos02 ~]# vim /etc/yum.repos.d/local.repo
[local]
name=centos7
baseurl=file:///mnt
enabled=1
gpgcheck=0

Mysql 数据库系统部署使用_centos_29

3) 安装 mariadb 客户

[root@centos02 ~]# yum -y install mariadb

4) 在 mysql 数据库授权 tom 用户完全控制权限通过主机 192.168.100.20 访问数据库服务

器写入数据

mysql> grant all on accp.* to 'tom'@'192.168.100.20' identified by 'pwd@123';
Query OK, 0 rows affected (0.00 sec)mysql> show grants for tom@192.168.100.20;
+-----------------------------------------------------------------------------------------------------------------+
| Grants for tom@192.168.100.20 |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'192.168.100.20' IDENTIFIED BY PASSWORD '*760F60073FD235571A5260444301DB22136ED604' |
| GRANT ALL PRIVILEGES ON `accp`.* TO 'tom'@'192.168.100.20' |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>

5)Linux 系统 Mysql 客户端远程访问 mysql 数据库

[root@centos02 ~]# mysql -h 192.168.100.10 -P 3306 -u tom -ppwd@123
MySQL [(none)]> insert into accp.student values ('xxx',20,'11012099911','111188889099997777');
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> select * from accp.1;
+-----------+--------+-------------+--------------------+
| 姓名 | 年龄 | 电话 | 身份证号码 |
+-----------+--------+-------------+--------------------+
| xxx | 20 | 11012099911 | 111188889099997777 |
| xxx | 18 | 13161295986 | 111345679124689018 |
+-----------+--------+-------------+--------------------+
2 rows in set (0.00 sec)
MySQL [(none)]>

3、授权远程 Windows 客户端访问 Mysql 数据库

1)在 Windows10 客户端安装 Navicat

Mysql 数据库系统部署使用_数据库_30

Mysql 数据库系统部署使用_centos_31

Mysql 数据库系统部署使用_数据库_32

2)mysql 服务器授权 192.168.100.30 通过 alice 用户密码为 pwd@1234 访问任意数据库和 表

mysql> grant all on *.* to 'alice'@'192.168.100.30' identified by 'pwd@1234';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for alice@192.168.100.30;
+----------------------------------------------------------------------------------------------------------------------------+
| Grants for alice@192.168.100.30 |
+----------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'alice'@'192.168.100.30' IDENTIFIED BY PASSWORD '*1012A2D81646DAEC166C0ACA539426FEECA3F616' |
+----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

3)客户端连接 mysql

Mysql 数据库系统部署使用_数据库_33

4)测试连接

Mysql 数据库系统部署使用_centos_34

5)使用客户端查看数据

Mysql 数据库系统部署使用_mysql_35

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: mysql数据库