1. 程式人生 > >Openwrt下mysql的使用

Openwrt下mysql的使用

說明
前段時間由於要求,在openwrt下添加了mysql,剛開始以為會很大,但是在make menuconfig下搜尋的時候發現好像只有mysql-server,並沒有mysql-client,編譯出來的韌體也只是比原來的韌體大了不到2M(flash是16M的,表示可以接受,如果你的flash是8M的,那麼你可以選擇安裝在U盤或者SD卡上)。

1.安裝mysql

make menuconfig

搜尋mysql,找到後打上“”號
在這裡插入圖片描述
在這裡插入圖片描述
mysql-server的附屬包有:libmysqlclient,libncursesw,uclibcxx,libreadline。那麼我們還要裝的最後一個就是libncurses這個包,打上“

”之後開始編譯。

編譯好之後刷進路由器裡。

2.配置mysql

在用ssh進去之後,我們可以看到/usr/bin下有mysqld這個服務,說明我們已經編譯進去了,接下來我們開始配置。

1.開啟配置檔案/etc/my.cnf,這裡我們主要修改的是datadir和tmpdir這兩個配置項,在這裡我把它放在了我掛載的sd卡上,可以根據自己的需求去存放你的mysql表

在這裡插入圖片描述

這裡的目錄需要手動去建立,不然初始化的時候會出錯!!!

3.初始化mysql

mysql_install_db  --force

在這裡我想說的是,如果你的初始化沒問題,那麼就可以跳過這一段,如果有如下問題

[email protected]:~# mysql_install_db --force
Installing MySQL system tables...
ERROR: 1049  Unknown database 'mysql'
110507 15:01:36 [ERROR] Aborting
110507 15:01:36 [Note] /usr/bin/mysqld: Shutdown complete

Installation of system tables failed!  Examine the logs in
/mnt/data/mysql/ for more information.
You can try to start the mysqld daemon with:
    shell> /usr/bin/mysqld --skip-grant &
and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:
    shell> /usr/bin/mysql -u root mysql
    mysql> show tables
Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /mnt/data/mysql/ that may be helpful.
Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.
Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the /usr/scripts/mysqlbug script!

這裡可以用一個成功初始化的mysql去替換掉(當然,這是我的解決方法,你可以自行解決)

4.啟動mysql
/etc/init.d/mysqld start

5.更改root密碼
mysqladmin -u root password ‘newpassword’

6.登陸mysql
mysql -u root -p

這裡回車之後會讓你輸入密碼,輸入的密碼不會顯示

在這裡插入圖片描述

OK,現在就可以操作mysql了!!!


作者:KOBE_ZERO
來源:CSDN
原文:https://blog.csdn.net/KOBE_ZERO/article/details/51546925
版權宣告:本文為博主原創文章,轉載請附上博文連結!