C++ 加 MySQL
打开cmd
输入 mysql
输入 mysql -u root -p
打开VisualStudio
VC/C目录
项目属性:点击c++->常规->附加包含目录->"选择C:\Program Files\MySQL\MySQL Server 8.0\include"
包含库文件->链接->常规->附加库目录->"选择C:\Program Files\MySQL\MySQL Server 8.0\lib"
写入库文件->链接器->输入->附加依赖项->libmysql.lib
libmysql.lib复制到c盘windows下system32文件夹下
PS C:\Users\86158> mysql -u root -p
Enter password: **************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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> show databases;
+
| Database |
+
| information_schema |
| mysql |
| performance_schema |
| py_sql |
| sakila |
| sys |
| test |
| world |
+
8 rows in set (0.00 sec)
mysql> create databases student_manager;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databases student_manager' at line 1
mysql> create database student_manager;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+
| Database |
+
| information_schema |
| mysql |
| performance_schema |
| py_sql |
| sakila |
| student_manager |
| sys |
| test |
| world |
+
9 rows in set (0.00 sec)
mysql> use student_manager;
Database changed
mysql> create table students(student_id int not null auto_increment primary key,student_name varchar(255) not null,stude
nt_class varchar(255) not null);
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+
| Tables_in_student_manager |
+
| students |
+
1 row in set (0.00 sec)
mysql> insert into students values(20221003174,'徐彬','计科2201');
ERROR 1264 (22003): Out of range value for column 'student_id' at row 1
mysql> insert into students values(1000,'徐彬','计科2201');
Query OK, 1 row affected (0.01 sec)