Win11系统设置计算机二级MySQL环境变量,设置创建数据库默认的字符集为utf8mb4,设置WampServer服务器phpMyAdmin程序。
下载软件
- NCRE官网的二级MySQL考试应用软件下载 : 点击下载
- WinRAR解压软件 :点击下载
- 微软常用运行库合集: 点击下载:来源https://www.mefcl.com/yxk-dreamcast/249
安装步骤
1. Win11首先安装微软常用运行库合集
2. 安装WinRAR解压软件
3. 解压安装二级MySQL应用软件WampServer
wampserver2.2e-php5.4.3-httpd2.2.22-mysql5.5.24-32b
安装过程要选择默认浏览器,选择Win11自带Microsoft Edge浏览器
选择浏览器路径:C:\Program Files (x86)\Microsoft\Edge\Application
选择浏览器文件:msedge
设置WampServer服务器phpMyAdmin
1. 设置Wampserver中文界面
右击任务栏wampserver图标,Language选择chinese,设置中文
2. 编辑Apache配置文件httpd.conf
点击任务栏wampserver图标,选择Apache,点击httpd.conf,
在配置文件httpd.conf 中查找127
把文件中127上面一行 Deny from all 改成 Alllow from all
保存关闭。
3. 编辑alias文件
点击任务栏wampserver图标,选择Apache,点击Alias目录,选择http://localhost/phpmyadmin,
点击Edit alias,编辑alias文件
同样把文件中127上面一行 Deny from all 改成 Alllow from all
保存关闭。
4. 启动phpMyAdmin
点击任务栏wampserver图标重新启动所有服务,点击phpMyAdmin,
浏览器就能打开phpMyAdmin。
phpMyAdmin “服务器连接校对” 默认字符排序规则是:utf8_general_ci,
更改排序规则为:utf8mb4_unicode_ci
配置MySQL环境变量,运行MySQL数据库
1. 右击开始菜单,选择系统
2. 点击“高级系统设置”
3. 点击“环境变量”,然后点击系统变量的Path,
点击新建,添加mysql路径:C:\wamp\bin\mysql\mysql5.5.24\bin
确定关闭。
4. 启动MySQL
任务栏输入CMD,点击运行“命令提示符”
输入命令:mysql -uroot -p
提示输入密码,因为默认没有密码,所以直接按回车键就能启动mysql
5. 设置MySQL字符集
查看当前版本命令:select version();
mysql> select version();
+------------+
| version() |
+------------+
| 5.5.24-log |
+------------+
1 row in set (0.00 sec)
查看当前字符集命令:show variables like “%char%”;
mysql> show variables like "%char%";
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.5.24\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.02 sec)
查看字符排序规则命令:show variables like “%colla%”;
mysql> show variables like "%colla%";
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | gbk_chinese_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
修改mysql配置文件my.ini,设置创建数据库默认的字符集为utf8mb4
打开my.ini文件,拉动到文件尾部
看到
[mysqld]
port=3306
在下面添加2句命令,创建数据库字符集和排序规则的设置:
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect=‘SET NAMES utf8mb4’
保存配置文件退出。
只要加这3句命令,其他都不要设置!否则二级MySQL数据库的中文会显示乱码!
6. 用MySQL控制台启动MySQL,查看字符集
点击任务栏wampserver图标重新启动所有服务,
再点击MySQL——MySQL控制台,按回车进入mysql
查询所有数据库命令: show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
查询创建数据库默认字符集和排序规则已经是utf8mb4
mysql> show variables like "%char%";
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.5.24\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)
mysql> show variables like "%colla%";
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | gbk_chinese_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+----------------------+--------------------+
3 rows in set (0.00 sec)
创建数据库命令: create database db_school;
查看创建的数据库字符集命令:show create database db_school;
mysql> create database db_school;
Query OK, 1 row affected (0.02 sec)
mysql> show create database db_school;
+-----------+--------------------------------------------------------------------------------------------------+
| Database | Create Database |
+-----------+--------------------------------------------------------------------------------------------------+
| db_school | CREATE DATABASE `db_school` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ |
+-----------+--------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)