CentOS下的C連線Mysql資料庫

2022-08-10 12:24:24 字數 1664 閱讀 1706

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'.

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、安裝支援庫

root

鍵入yum search mysql

出現

#include 

#include

#include

mysql *conn_ptr;

int main(void)

conn_ptr = mysql_real_connect(conn_ptr,"127.0.0.1","root","","mysql",3306,0,null);

if (conn_ptr)

else

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!

CentOS 下使用yum 命令安裝MySQL

日期 2017 12 09 字型 大中小 centos linux下使用yum 命令安裝mysql過程記錄。1.檢視伺服器中有沒有安裝過mysql 1.檢視有沒有安裝包 yum list mysql 移除已經安裝的mysql yum remove mysql mysql server mysql l...

Windows環境下利用Qt連線MYSQL資料庫

在windows下面利用qt開發資料庫應用,如mysql,首先,我們必須利用原始碼編譯mysql驅動庫 1 安裝qt sdk win opensource 2010.02.1.exe 此時,qt安裝了qt creator,假定目錄為 e qt 2010.02.1 可以選擇安裝mingw 此時,e q...

centos下的不同主機間冷備份mysql資料庫

假定192.168.1.1為生產環境主機a,作業系統為centos,a上安裝有mysql。假定 192.168.1.2為備份主機b,作業系統為centos,b未安裝mysql。1 在a上建立使用者備份的mysql使用者,需授予select lock process許可權 2 在b上安裝mysql客戶...