程序员人生 网站导航

[置顶] freebsd 安装 mysql

栏目:数据库应用时间:2014-12-24 08:34:08

1. freebsd 这个系统说实话 真的没有ubuntu 方便 ,要安装个软件, apt-get install 下就能够了,而在freebsd 下面只能在ports 下去装,但通常情况下总是没资源,坑啊
所以只能自己 下包,自己装了 


1. 首先下 mysql⑸.1.70.tar.gz

tar -zxvf mysql⑸.1.70.tar.gz

cd mysql⑸.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 
root@gyl:/usr/local/mysql/bin # ./mysqld_safe --user=mysql &

关闭mysql 
root@gyl:/usr/local/mysql/bin # ./mysqladmin -uroot -p shutdown

进入mysql 
root@gyl:/usr/local/mysql/bin # ./mysql -u root -p

用navicate 去连的时候 要开启权限
root@gyl:/usr/local/mysql/bin # ./mysql -u root -p
mysql> 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"

应当是 里面的代码的链接路径不对,但是又没办法改代码,只能改路径

root@gyl:/usr/local/mysql/lib/mysql # ln -s libmysqlclient.so.16 /usr/lib/libmysqlclient.so
root@gyl:/usr/local/mysql/lib/mysql # cp libmysqlclient.so.16 /usr/lib

这样就能够了,大告功成,记下,免得以后又忘记了




------分隔线----------------------------
------分隔线----------------------------

最新技术推荐