此文章包含2023至2024年物联网技能大赛及金砖的数据库系统维护相关题目及答案


# Windows离线安装MYSQL

将U盘中mysql文件夹解压,新建data文件夹和.ini文件

[mysqld]
datadir =...
basedir =...

安装-初始化-启动(在bin文件夹中打开)

mysqld --install #安装
mysqld --initialize --user=mysql --console #初始化
net start mysql #启动服务

# 更改ROOT账户密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

# 查看用户配置

use mysql;
select User,Host from user

# 为MySQL配置远程访问功能

找到配置文件

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

登录数据库后授予权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password';  
FLUSH PRIVILEGES;

# 查询/操作

# 显示所有可用字符集排序方式

show charset;

# 显示当前数据库系统最大连接数

SHOW VARIABLES LIKE 'max_connections';

# 显示当前数据库系统表级锁竞争状态

show status like '%table_lock%';

# 查询数据库中所有数据表和每个表的记录数的SQL语句

SELECT
	table_name AS 表名,
	table_rows AS 记录条数 
FROM
	information_schema.TABLES 
WHERE
	table_schema = 'nleedge';

# 导入数据库

#使用.sql脚本

source xxx.sql