MySQL
ini配置
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录 ----------是你的文件路径-------------
basedir=E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64
# 设置mysql数据库的数据的存放目录 ---------是你的文件路径data文件夹自行创建
#datadir=E:\4_SOFTware\MySQL9.1\MySQL_Data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
#default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4
初始配置
E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin>mysqld --initialize --console
2024-11-16T02:50:47.784134Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2024-11-16T02:50:47.791016Z 0 [System] [MY-013169] [Server] E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin\mysqld.exe (mysqld 9.1.0) initializing of server in progress as process 860
2024-11-16T02:50:47.828926Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-11-16T02:50:48.360971Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-11-16T02:50:50.172133Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Ie/Z9aSzh7jT
2024-11-16T02:50:52.007493Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin>
E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin>mysqld --install mysql
Service successfully installed.
E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin>net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。
E:\4_SOFTware\MySQL9.1\mysql-9.1.0-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 9.1.0
Copyright (c) 2000, 2024, 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 '174496';
Query OK, 0 rows affected (0.02 sec)
mysql>
启动服务
net start mysql
连接数据库
C:\Windows\system32>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 9.1.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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>
Navicat
建立MySQL连接
连接 -> mysql -> 常规
导入数据库
右键要导入到的数据库 -> 运行SQL文件
基本操作
MySQL操作
mysql> SELECT User FROM mysql.user;
+------------------+
| User |
+------------------+
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
+------------------+
4 rows in set (0.00 sec)
mysql>
查看和创建数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
mysql>
mysql> create database MyDB_test;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb_test |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
数据库的编码方式
直接创建的数据库,数据库的编码方式是 MySQL 默认的编码方式 latin1 (单字节编码) ,通常我们会在数据库中存放中文数据,所以最好把数据库的编码方式设置成 utf-8 ,这样中文才能正常显示。
使用
create database 数据库名 character set utf8;
或create database MyDB_three charset utf8;
创建数据库并设置数据库的字符编码。修改已创建数据库的编码方式
使用
alter database 数据库名 character set utf8;
修改数据库编码
mysql> create database MyDB_two character set utf8;
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb_test |
| mydb_two |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)
mysql>
数据库创建信息
使用
show create database 数据库名;
显示数据库的创建信息。
使用数据库
进入或切换数据库
使用
use 数据库名
进入或切换数据库。显示当前数据库
显示当前数据库
select database();
mysql> use mydb_two
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mydb_two |
+------------+
1 row in set (0.00 sec)
mysql> use mydb_test
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mydb_test |
+------------+
1 row in set (0.00 sec)
mysql>
参考
Navicat使用快速入门教程_navicat使用教程-CSDN博客
MySql-8.0.26安装详细教程(保姆级)_mysql8026安装教程图解-CSDN博客