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了!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值