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

在这里我想说的是,如果你的初始化没问题,那么就可以跳过这一段,如果有如下问题

root@OpenWrt:~# 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
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/weixin_43025071/article/details/83546945