路由器搭建网站:Mysql-server配置

  • 2017-08-21
  • 302
  • 0
  • 0

一、安装MySQL数据库(在backfire10.3版本中,package已经包含mysql-server.ipk)因此可以直接通过opkg安装。

opkg update
opkg install mysql-server

K3空间偏小,无法安装mysql,提示看见不足:

[K3 ~]# opkg install mysql-server
Installing mariadb-server (5.5.58-1) to root...
Downloading http://pkg.entware.net/binaries/armv7/mariadb-server_5.5.58-1_armv7soft.ipk
Installing resolveip (2) to root...
Downloading http://pkg.entware.net/binaries/armv7/resolveip_2_armv7soft.ipk
Configuring resolveip.
Configuring mariadb-server.
Collected errors:
 * copy_file_chunk: write: No space left on device.
 * opkg_conf_write_status_files: Couldn't close //opt/lib/opkg/status: No space left on device.

使用硬盘盒果断插上网友送的500GB笔记本硬盘,

将opkg安装目录修改到硬盘上:

[K3 /tmp/share/sda1/opt]# vi /opt/etc/opkg.conf 
src/gz packages http://pkg.entware.net/binaries/armv7
dest root /tmp/share/sda1
dest ram /opt/tmp
lists_dir ext /opt/var/opkg-lists
option tmp_dir /tmp/share/sda1/opt/tmp

 

二、设置mysql配置文件(/etc/my.cnf)

1. 修改数据库存放的位置(在/etc/my.cnf中找到如下配置)

datadir            =/mnt/data/mysql
tmpdir             =/mnt/data/tmp

更改为:

datadir             =/tmp/share/sda1/mysqldata/mysql     #将数据库放置到U盘对应分区上存储
tmpdir              =/tmp/share/sda1/mysqldata/tmp       #将数据库临时文件夹存放到U盘对应分区上

#本人的数据库存放在硬盘,也就是/tmp/share/sda1/,大家根据自己的需要修改

2. 修改数据库的绑定地址(找到bind-address属性)

bind-address        =127.0.0.1

更改为:

bind-address        =0.0.0.0

修改的目的:允许远程访问。

保存修改,并退出编辑。

3. 创建数据库存放文件夹(若my.cnf中datadir以及tmpdir对应存储位置不存在的话,进行此操作,否则跳过此步骤)

mkdir /tmp/share/sda1/mysqldata/
mkdir /tmp/share/sda1/mysqldata/mysql
mkdir /tmp/share/sda1/mysqldata/tmp

4. 创建database(执行如下操作)

/tmp/share/sda1/opt/bin/mysql_install_db --force

出现报错:

[K3 /tmp/share/sda1/opt/bin]# /tmp/share/sda1/opt/bin/mysql_install_db --force

FATAL ERROR: Could not find mysqld

The following directories were searched:

    /opt/bin
    /opt/libexec
    /opt/sbin
    /opt/bin

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

The latest information about mysql_install_db is available at
https://mariadb.com/kb/en/installing-system-tables-mysql_install_db

修改后:

[K3 /tmp/share/sda1/opt/bin]# ./mysql_install_db --basedir=/tmp/share/sda1/opt/
./mysql_install_db: line 342: hostname: not found
WARNING: The host '' could not be looked up with /tmp/share/sda1/opt//bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in './data' ...
180414 0:50:40 [Note] /tmp/share/sda1/opt//bin/mysqld (mysqld 5.5.58-MariaDB) starting as process 945 ...
mysqld --lc-messages-dir="/tmp/share/sda1/opt/share/mysql/"

 

三、启动MySQL数据库

1. 启动mysql守护进程

/etc/init.d/mysqld enable
/etc/init.d/mysqld start

2. 启动mysql server交互进程:

使用过mysql的亲们都清楚,mysql数据库的操作需要对应用户有权限才行的。在刚刚建成的数据库还没有对用户设置密码。那该如何设置呢?有如下两种方法:

方法一:

使用mysqladmin命令预先设置对应用户mysql使用密码,以root用户为例:

/usr/bin/mysqladmin -u root password XXXXXX   
# XXXXXX 是为root用户设置的密码

设置远程登录MySQL账号:

mysql> use mysql;
mysql> GRANT ALL ON *.* TO admin@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;

#这句话的意思 ,允许任何IP地址(上面的 % 就是这个意思)的电脑 用admin帐户 和密码(admin)来访问这个MySQL Server
#必须加类似这样的帐户,才可以远程登陆。 root帐户是无法远程登陆的,只可以本地登陆

 

关闭mysqld服务

killall mysqld

重启mysqld服务

/etc/init.d/mysqld start

在设置完密码和权限之后,以root用户登录Mysql:

mysql -u root -p

ok 到此Mysql就能正常登录和使用了。

查看原文

评论

偷偷告诉你,这还毛都没有 T T

发表评论