1.安装Mysql
sudo apt-get install mysql-server
2.安装之后 用户为root 密码为输入的密码
3安装navicat
进入
http://www.navicat.com/en/download/download.html
下载安装包,navicat100_mysql_en.tar.gz 进入 解压后的文件夹,运行start_navicat
建立一个连接,发现连不上,出现
运行
$mysql -u root 出现错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$mysql -u root -p mysql进入之后
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
将密码改为123456
4 c语言测试mysql
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
int main(void)
{
const char *host = "localhost";
const char *user = "root";
const char *pass = "123456";
const char *db = "test";
/* 定义mysql变量 */
MYSQL mysql;
MYSQL_RES *rs;
MYSQL_ROW row;
mysql_init(&mysql); /* 初始化 */
/* 连接数据库 */
if (!mysql_real_connect(&mysql, host, user, pass, db, 0, NULL, 0))
{
printf("%s", mysql_error(&mysql));
}
char *sql = "select name,pass from user order by rand()";
if (mysql_query(&mysql, sql)!=0)
{ /* 查询 */
printf( "%s", mysql_errno(&mysql), mysql_error(&mysql));
}
rs = mysql_store_result(&mysql); /* 获取查询结果 */
while ((row = mysql_fetch_row(rs)))
{ /* 获取每一行记录 */
printf( "%s---%s", row[0], row[1]);
}
mysql_free_result(rs); /* 释放结果集 */
mysql_close(&mysql); /* 关闭连接 */
return 1;
}
1.若出现mysql.h: 没有那个文件或目录
运行:$sudo apt-get install libmysqlclient15-dev
出现某个依赖包未能安装
运行:$sudo apt-get install
运行:$sudo apt-get install libmysqlclient15-dev
在/usr/include/mysql下 出现爱年mysql.h
2.编译
gcc $(mysql_config --cflags) mysql_test.c -o mysql_t $(mysql_config --libs)
eclipse下build出错
Project->Properties->C/C++Build->Settings->GCC C++Linker->Libraries
在Libraries(-l)中增加lmysqlclient即可