0

0

CentOS下的C连接MySQL数据库

php中文网

php中文网

发布时间:2016-06-07 17:02:09

|

1264人浏览过

|

来源于php中文网

原创

1、修改密码因为默认是没有密码的为了安全先修改密码,方法是:先停止mysql/etc/init.d/mysql stop-- 安全模式启动[root@mysql

1、修改密码

因为默认是没有密码的为了安全先修改密码,方法是:

先停止mysql

/etc/init.d/mysql stop

--  安全模式启动
[root@mysql var]#mysqld_safe --skip-grant-tables &
[1] 10912
[root@mysql var]# 110407 17:39:28 mysqld_safe Logging to '/usr/local/mysql/var//mysql.chinascopefinanical.com.err'.
110407 17:39:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var/

[root@mysql var]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.1.41-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed

mysql> update user set password=password("yourpasswd) where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

 


完成上面的操作之后,/etc/init.d/mysqld restart重启mysql

 


完成上面的操作之后密码就设定好了。

 


2、安装支持库

ecshop
ecshop

本版本全面兼容php5.6+,并且修复了许多官方程序的低级代码bug。在apache 2.4.17+php5.6.15环境下测试通过,人格保证无毒无木马,仅仅是一名ecshop热爱者心血来潮之作。ecshop编译更新日志:1、加入最新官方补丁。2、修改数据库连接底层为mysqli, 现在完美无缺了。3、再次对所有代码进行细节修复。4、adminers更新至1.1.2, 在线管理数据库的神器。5、测

下载

 


root

键入yum search mysql

出现

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ta139.com
 * extras: mirrors.ta139.com
 * updates: mirrors.ta139.com
================================ Matched: mysql ================================
mod_auth_mysql.i386 : 使用 MySQL 数据库的 Apache 万维网服务器的基础验证。
qt-MySQL.i386 : 用于 Qt 的 SQL 类别的 MySQL 驱动程序。
MySQL-python.i386 : 一个到 MySQL 的界面
apr-util-mysql.i386 : APR utility library MySQL DBD driver
bytefx-data-mysql.i386 : MySQL database connectivity for Mono
freeradius-mysql.i386 : freeradius 的 MySQL 绑定
freeradius2-mysql.i386 : MySQL support for freeradius
libdbi-dbd-mysql.i386 : libdbi 的 MySQL 插件
mysql.i386 : MySQL client programs and shared libraries
mysql-bench.i386 : MySQL benchmark scripts and data
mysql-connector-odbc.i386 : MySQL 的 ODBC 驱动程序。
mysql-devel.i386 : Files for development of MySQL applications

mysql-server.i386 : The MySQL server and related files
mysql-test.i386 : The test suite distributed with MySQL
pdns-backend-mysql.i386 : MySQL backend for pdns
perl-DBD-MySQL.i386 : perl 的 MySQL 接口
perl-DBD-Pg.i386 : Perl 的 PostgresSQL 界面
php-mysql.i386 : 一个用于使用 MySQL 数据库的 PHP 程序的模块。
php-pdo.i386 : A database access abstraction module for PHP applications
php-pear-MDB2-Driver-mysql.noarch : MySQL MDB2 driver
php53-mysql.i386 : A module for PHP applications that use MySQL databases
php53-pdo.i386 : A database access abstraction module for PHP applications
qt4-mysql.i386 : MySQL drivers for Qt's SQL classes
rsyslog.i386 : Enhanced system logging and kernel message trapping daemon
rsyslog-mysql.i386 : MySQL support for rsyslog


unixODBC.i386 : 一个用于 Linux 的完整的 ODBC 驱动程序管理器。

红色部分就是我们要的:
yum install mysql-devel-i386 开始安装

3、编写程序mysql.c


#include
#include
#include
MYSQL *conn_ptr;

int main(void){
 
 conn_ptr = mysql_init(NULL);
 if (!conn_ptr)
 {
  fprintf(stderr,"mysql_init failed!\n");
  return (-1);
 }
 
 conn_ptr = mysql_real_connect(conn_ptr,"127.0.0.1","root","","mysql",3306,0,NULL);
 if (conn_ptr)
 {
  printf ("connection succeed!\n");
 }
 else{
  printf ("connection failed!\n");
  return (-2);
 }
 
 mysql_close(conn_ptr);
 printf ("connection close!\n");
 
 return 0;

}

4、编译程序
gcc -o mydbcon -I /usr/include/mysql/ -L /usr/lib/mysql -lmysqlclient mysql.c

5、执行程序
./mydbcon

connection succeed!
connection close!

linux

相关专题

更多
虚拟号码教程汇总
虚拟号码教程汇总

本专题整合了虚拟号码接收验证码相关教程,阅读下面的文章了解更多详细操作。

29

2025.12.25

错误代码dns_probe_possible
错误代码dns_probe_possible

本专题整合了电脑无法打开网页显示错误代码dns_probe_possible解决方法,阅读专题下面的文章了解更多处理方案。

20

2025.12.25

网页undefined啥意思
网页undefined啥意思

本专题整合了undefined相关内容,阅读下面的文章了解更多详细内容。后续继续更新。

37

2025.12.25

word转换成ppt教程大全
word转换成ppt教程大全

本专题整合了word转换成ppt教程,阅读专题下面的文章了解更多详细操作。

6

2025.12.25

msvcp140.dll丢失相关教程
msvcp140.dll丢失相关教程

本专题整合了msvcp140.dll丢失相关解决方法,阅读专题下面的文章了解更多详细操作。

2

2025.12.25

笔记本电脑卡反应很慢处理方法汇总
笔记本电脑卡反应很慢处理方法汇总

本专题整合了笔记本电脑卡反应慢解决方法,阅读专题下面的文章了解更多详细内容。

6

2025.12.25

微信调黑色模式教程
微信调黑色模式教程

本专题整合了微信调黑色模式教程,阅读下面的文章了解更多详细内容。

5

2025.12.25

ps入门教程
ps入门教程

本专题整合了ps相关教程,阅读下面的文章了解更多详细内容。

4

2025.12.25

苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

218

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
简单聊聊mysql8与网络通信
简单聊聊mysql8与网络通信

共1课时 | 771人学习

Swoft2.x速学之http api篇课程
Swoft2.x速学之http api篇课程

共16课时 | 0.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号