mySql的安装和运行
mySql的安装和运行
1. 从 mySql 官网下载了 mysql-8.0.21-winx64.zip
2. 解压到 F:\mysql-8.0.21-winx64 ,mysqld.exe是一个服务器程序 ,它在F:\mysql-8.0.21-winx64\bin目录内。mysql.exe是一个管理服务器的控制台程序,也在该bin目录下。
3. 在F:\mysql-8.0.21-winx64目录编辑一个my.ini文件,用来配置mysqld和mysql的选项:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=F:\mysql-8.0.21-winx64
# 设置mysql数据库的数据的存放目录
datadir=F:\mysql-8.0.21-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
4. 以管理员身份运行 cmd。如下图:
5. 运行 mysqld --initialize-insecure
过程比较长,会产生 data目录以及该目录里的一系列文件
6. mysqld --install 安装服务
7. net start mysql 启动服务
8. mysql -u root 以root用户运行管理数据库的控制程序。
下面是运行的过程:
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\windows\system32>mysqld --initialize-insecure
C:\windows\system32>mysqld install
Service successfully installed.
C:\windows\system32>net start mysql
MySQL 服务正在启动 ...
MySQL 服务已经启动成功。
C:\windows\system32>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
C:\windows\system32>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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>
一旦启动mysql成功,提示符是 mysql>,下面展示 a. 创建studentAdmin数据库 b. 在studentAdmin数据库里创建student表. c.增加zhangsan和lisi两个学生到student表里. d. 查询并显示2个学生。
mysql> create database studentAdmin
-> ;
Query OK, 1 row affected (0.29 sec)
mysql> use studentAdmin
Database changed
mysql> create table student(id integer,name varchar(100) );
Query OK, 0 rows affected (0.63 sec)
mysql> INSERT INTO student (id , name) VALUES (1001,"zhangsan") ;
Query OK, 1 row affected (0.11 sec)
mysql> INSERT INTO student (id , name) VALUES (1002,"lisi") ;
Query OK, 1 row affected (0.10 sec)
mysql> select * from student
-> ;
+------+----------+
| id | name |
+------+----------+
| 1001 | zhangsan |
| 1002 | lisi |
+------+----------+
2 rows in set (0.00 sec)
mysql> show tables
-> ;
+------------------------+
| Tables_in_studentadmin |
+------------------------+
| student |
+------------------------+
1 row in set (0.05 sec)
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studentadmin |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
参考:
1. https://blog.csdn.net/weixin_42869365/article/details/83472466
2 运行服务失败参考 https://blog.csdn.net/shinny195/article/details/82319218
mySql的安装和运行相关教程