专业编程基础技术教程

网站首页 > 基础教程 正文

Mysql 8.4数据库安装、新建用户和数据库、表单

ccvgpt 2025-01-14 11:11:41 基础教程 1 ℃

1、下载MySQL数据库

 yum install -y wget perl net-tools libtirpc
 # 安装wget和perl、net-tools、libtirpc
 wget https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.0-1.el9.x86_64.rpm-bundle.tar
 # 下载安装包
 tar -xvf mysql-8.4.0-1.el9.x86_64.rpm-bundle.tar
 # 解压安装包
 rpm -ivh mysql-community-common-8.4.0-1.el9.x86_64.rpm
 rpm -ivh mysql-community-client-8.4.0-1.el9.x86_64.rpm
 rpm -ivh mysql-community-client-plugins-8.4.0-1.el9.x86_64.rpm
 rpm -ivh mysql-community-libs-8.4.0-1.el9.x86_64.rpm
 rpm -ivh mysql-community-icu-data-files-8.4.0-1.el9.x86_64.rpm
 rpm -ivh mysql-community-server-8.4.0-1.el9.x86_64.rpm
 # 安装MySQL

2、配置数据库

 systemctl start mysqld
 # 启动数据库
 systemctl enable mysqld
 # 设置开机启动
 cat /var/log/mysqld.log
 # 查看下默认密码

3、修改默认管理员密码

 mysql -uroot -p
 # 进入数据库
 ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hadesr^000';
 #修改下root初始密码,密码为:Hadesr^000
 
 FLUSH PRIVILEGES;
 # 刷新下权限
 
 exit
 # 退出
 mysql -uroot -pHadesr^000
 # 再重新进入,就需要新密码了

4、创建用户和数据库

 CREATE USER 'Hadesr'@'localhost' IDENTIFIED BY 'Hadesr^000';
 # 创建用户 Hadesr

如果需要外部远程访问,需要把'Hadesr'@'localhost'改成'Hadesr'@'%'

 create database wifite character set utf8 collate utf8_bin;
 # 创建 wifite 数据库
 GRANT ALL PRIVILEGES ON wifite.* TO 'Hadesr'@'localhost';
 # wifite数据库用户赋权
 
 FLUSH PRIVILEGES;
 # 刷新下权限
 
 SHOW DATABASES;
 # 查看数据库中的所有数据库
 ----------------------
 mysql> SHOW DATABASES;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | performance_schema |
 | sys                |
 | wifite             |
 +--------------------+
 5 rows in set (0.00 sec)

wifite.* 为数据库名字,这里只把wifite库授权给Hadesr用户,库名改成*.*,则把所有库都授权给Hadesr用户

Mysql 8.4数据库安装、新建用户和数据库、表单

5、创建表

1、进入wifite 库

 USE wifite;

2、创建表

 CREATE TABLE `dever` (
 `name` text NOT NULL,
 `ip` varchar(15) NOT NULL,
 `username` text NOT NULL,
 `password` text NOT NULL,
 `port` char(32)
 ) ;

3、查询表和表结构

 show  tables;
 # 查询 wifite 库中表
 ---------------------
 
 mysql> show  tables;
 +--------------------+
 | Tables_in_wifite   |
 +--------------------+
 | dever              |
 +--------------------+
 
 select * from dever;
 # 查询 net_dev 表结构
 
 ----------------------------------------------------------------------------
 mysql> select * from dever;
 +------+----------+----------+------------+------+
 | name | ip       | username | password   | port |
 +------+----------+----------+------------+------+
 | Test | 10.1.2.3 | Hadesr   | hadesr.com | 22   |
 +------+----------+----------+------------+------+

6、输入信息

1、插入数据

 INSERT INTO `dever`(`name`,`ip`,`username`,`password`,`port`) VALUES ('Test','10.1.2.3','Hadesr','123456','22');

2、删除信息

 delete from dever where name = "Test";

3、更新信息

 update wifite.dever set password='hadesr.com' where name='Test';

4、使用 Navicat Premium 编辑设备信息

MySQL 下插入设备信息命令繁琐,设备多了不方便,可以使用Navicat Premium图形化进行操作



最近发表
标签列表