
mysql的基础我们之前已经学过后面我们只关心使用要使用C语言连接mysql需要使用mysql官网提供的库大家可以去官网下载我们使用C接口库来进行连接要正确使用我们需要做一些准备工作保证mysql服务有效在官网上下载合适自己平台的mysql connect库以备后用[rootiZ5waahoxw3q2bZ ~]# mysql -uroot -p Enter password: 输入之前设置的密码1234561.简单创建mysql use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql select User,Host from user; -------------------------- | User | Host | -------------------------- | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | -------------------------- 3 rows in set (0.00 sec) 如果发现还有其他用户比如zhangsan的可以用如下的 mysql drop user zhangsan%;建立一个本地用户mysql create user connectorlocalhost identified by 123456; Query OK, 0 rows affected (0.00 sec) mysql select User,Host from user; -------------------------- | User | Host | -------------------------- | connector | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | -------------------------- 4 rows in set (0.00 sec)登陆我们新创建的本地的connector终端1 mysql create user connectorlocalhost identified by 123456; Query OK, 0 rows affected (0.00 sec) mysql select User,Host from user; -------------------------- | User | Host | -------------------------- | connector | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | -------------------------- 4 rows in set (0.00 sec) 终端2 [rootiZ5waahoxw3q2bZ ~]# mysql -uconnector -p Enter password: mysql创建一个conn数据库终端1 mysql create database conn; Query OK, 1 row affected (0.00 sec)给connector这个conn数据库所有权限终端1 mysql grant all on conn.* to connectorlocalhost; Query OK, 0 rows affected (0.00 sec)刷新一下权限终端1 mysql flush privileges; Query OK, 0 rows affected (0.00 sec)终端2 刷新前 mysql show databases; -------------------- | Database | -------------------- | information_schema | -------------------- 1 row in set (0.00 sec) 刷新后 mysql show databases; -------------------- | Database | -------------------- | information_schema | | conn | -------------------- 2 rows in set (0.00 sec) mysql use conn; Database changed mysql show tables; Empty set (0.00 sec)我们发现用Windows的终端去连接连接不上是因为我们设置的是localhostC:\Users\wozhamysql -uconnector -h121.40.196.90 -p 8080 -pEnter password: ******ERROR 2003 (HY000): Cant connect to MySQL server on 121.40.196.90:3306 (10060)如果想要连接可以更改Host。感谢你的观看期待我们下次再见