freebsd 安裝 mysql

來源:互聯網
上載者:User

標籤:style   io   ar   color   os   sp   檔案   on   div   

1. freebsd 這個系統說實話 真的沒有ubuntu 方便 ,要安裝個軟體, apt-get install 下就可以了,而在freebsd 下面只能在ports 下去裝,但通常情況下總是沒資源,坑啊
所以只能自己 下包,自己裝了 


1. 首先下 mysql-5.1.70.tar.gz

tar -zxvf mysql-5.1.70.tar.gz
cd mysql-5.1.70
./configure --prefix=/usr/local/mysql
make WITH_CHARSET=utf8 WITH_PROC_SCOPE_PTH=yes BUILD_OPTIMIZED=yes BUILD_STATIC=yes SKIP_DNS_CHECK=yes WITHOUT_INNODB=yes install clean

pw groupadd mysql

pw useradd mysql -g mysql 

/usr/local/mysql/bin/mysql_install_db --user=mysql
cp /usr/local/mysql/share/mysql/my-large.cnf /etc/my.cnf
cd /usr/local/mysql

chown -R root .
chown -R mysql var
chown -R mysql var/mysql/. 

chgrp -R mysql .    # .號千萬不要忘了寫
/usr/local/mysql/bin/mysql_install_db --user=mysql
./mysqld_safe --user=mysql &
// 裝好之後 初始密碼沒有 重設密碼 ./mysqladmin -uroot -p password 123456會提示 enter password: 直接按enter 鍵即可(這裡要輸的原來密碼,原來的密碼沒有)
啟動mysql [email protected]:/usr/local/mysql/bin # ./mysqld_safe --user=mysql &
關閉mysql [email protected]:/usr/local/mysql/bin # ./mysqladmin -uroot -p shutdown

進入mysql [email protected]:/usr/local/mysql/bin # ./mysql -u root -p
用navicate 去連的時候 要開啟許可權[email protected]:/usr/local/mysql/bin # ./mysql -u root -pmysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;mysql> FLUSH PRIVILEGES;mysql> EXIT
寫段代碼測試下
#include <iostream>#include <string.h>#include "mysql.h" //安裝的mysql的標頭檔所在的位置using namespace std;string host = "192.168.67.130";string user = "root";string pwd = "123456";string dbname = "test";string sql = "select * from user";unsigned int port = 3306; // int status;int main(){MYSQL *mysql;mysql = mysql_init(0);MYSQL_RES *result;MYSQL_ROW row;if (mysql_real_connect(mysql, host.c_str(), user.c_str(), pwd.c_str(), dbname.c_str(), port, NULL, CLIENT_FOUND_ROWS) == NULL){cout << "connect failure!" << endl;return EXIT_FAILURE;}else{cout << "connect success!" << endl;}mysql_set_character_set(mysql, "gbk");status = mysql_query(mysql, sql.c_str());if (status != 0){cout << "query failure!" << endl;}cout << "the status is :" << status << endl;result = mysql_store_result(mysql);while (row = mysql_fetch_row(result)){cout << row[1] << "|" << row[2] << endl;}mysql_free_result(result);mysql_close(mysql);}

g++ -o testmysql testmysql.cpp -lmysqlclient -I /usr/local/mysql/include/mysql -L /usr/local/mysql/lib/mysql/

編譯可以成功,但是執行 ./testmysql 時提示如下錯誤Shared object "libmysqlclient.so.16" not found, required by "testmysql"

應該是 裡面的代碼的連結路徑不對,但是又沒辦法改代碼,只能改路徑
[email protected]:/usr/local/mysql/lib/mysql # ln -s libmysqlclient.so.16 /usr/lib/libmysqlclient.so[email protected]:/usr/local/mysql/lib/mysql # cp libmysqlclient.so.16 /usr/lib
這樣就可以了,大告功成,記下,免得以後又忘記了



freebsd 安裝 mysql

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.