mysql 有自己的官网和其他gitlab的下载路径,但可能速度过慢或者不好找到源码,我是使用gitee的路径下载的。
mysql 5.5.62 : gitee连接
mysql依赖该ncueses库,所有首先需要编译该库。
官网地址
http://ftp.gnu.org/pub/gnu/ncurses/
下载地址
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
mysql依赖该ncueses库,所有首先需要编译该库。
tar zxvf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure CC=arm-linux-gnu-gcc --prefix=$PWD/out --host=arm-linux --with-shared
注意:该命令需要根据自己交叉编译工具自行修改
make
这里有人就问了,我们是交叉编译ARM 版本的mysql, 为啥还要编译X86版本的呢? 有移植经验的同学会知道: 编译过程中要生成一些工具,并在编译的时候要执行。mysql 也一样, 编译的时候需要执行以下6 个工具来完成编译:
extra/comp_err
scripts/comp_sql
sql/gen_lex_hash
sql/gen_lex_token
extra/protobuf/protoc
libmysql/libmysql_api_test
注意:前三个工具是5.5 版本中有,后三个工具在5.7版本中才有,没有测试过其他版本,读者可根据自己的情况判断。该文件是需要编译完成后拷贝到到交叉编译的源码中。
其他人可能会使用cmake ./ 直接编译,这样会导致编译出来的文件和源码混合到一起了,我个人的习惯是创建一个build目录,将编译过程中产生的文件都放到build中。所有此处运行的命令如下:
tar -zxvf mysql-5.5-62.tar.gz
mkdir build #建一个单独的文件夹来进行编译
cd build
cmake …
make
出错问题:
报错1:
– Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
解决1:
sudo apt install libncurses5-dev
报错2:
– Library mysqlclient depends on OSLIBS -lpthread;m;dl
Warning: Bison executable not found in PATH
CMake Error at cmake/bison.cmake:78 (MESSAGE):
Bison (GNU parser generator) is required to build MySQL.Please install
bison.
Call Stack (most recent call first):
sql/CMakeLists.txt:207 (RUN_BISON)
解决2:
sudo apt install bison
./gen_lex_hash: 1: ./gen_lex_hash: Syntax error: word unexpected (expecting ")")
sql/CMakeFiles/GenServerSource.dir/build.make:69: recipe for target 'sql/lex_hash.h' failed
make[2]: *** [sql/lex_hash.h] Error 2
make[2]: *** Deleting file 'sql/lex_hash.h'
CMakeFiles/Makefile2:4784: recipe for target 'sql/CMakeFiles/GenServerSource.dir/all' failed
make[1]: *** [sql/CMakeFiles/GenServerSource.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 15%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/random.cpp.o
[ 15%] Building C object strings/CMakeFiles/strings.dir/ctype-utf8.c.o
/home/qinb/mysql-5.5-arm/mysql-server-5.5/scripts/comp_sql: 1: /home/qinb/mysql-5.5-arm/mysql-server-5.5/scripts/comp_sql: Syntax error: word unexpected (expecting ")")
scripts/CMakeFiles/GenFixPrivs.dir/build.make:62: recipe for target 'scripts/mysql_fix_privilege_tables_sql.c' failed
make[2]: *** [scripts/mysql_fix_privilege_tables_sql.c] Error 2
CMakeFiles/Makefile2:5205: recipe for target 'scripts/CMakeFiles/GenFixPrivs.dir/all' failed
make[1]: *** [scripts/CMakeFiles/GenFixPrivs.dir/all] Error 2
解决:
sudo cp extra/comp_err /usr/bin/
sudo cp scripts/comp_sql /usr/bin/
sudo cp sql/gen_lex_hash /usr/bin/
sudo cp sql/gen_lex_token /usr/bin/
sudo cp extra/protobuf/protoc /usr/bin/
sudo cp libmysql/libmysql_api_test /usr/bin/
################################################
####### General crosscompile toolchain file
################################################
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)
#LINK_DIRECTORIES(/opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi)
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
#set(LOCAL_NCURSES_DIR /home/qinb/boost/out)
#set(BOOST_NCURSES_DIR /home/qinb/boost/out/include)
#set(BOOST_NCURSES_DIR /home/qinb/boost/out/lib)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
################################################################
####### The special configuration MACRO for mysql
################################################################
SET(WITH_UNIT_TESTS OFF) ## disable unit_test
SET(DEFAULT_CHARSET utf8) ## the default charset
SET(DEFAULT_COLLATION utf8_general_ci)
SET(EXTRA_CHARSETS all) ## Which extra character sets to include:
SET(STACK_DIRECTION 1) ## Stack grows direction
## If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts
## to issue such a statement receives the following error message:
## ERROR 1148: The used command is not allowed with this MySQL version
SET(ENABLED_LOCAL_INFILE 1)
#SET(WITH_EMBEDDED_SERVER TRUE)
SET(HAVE_LLVM_LIBCPP OFF)
SET(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE 1)
SET(HAVE_IB_GCC_SYNC_SYNCHRONISE 1)
SET(HAVE_IB_GCC_ATOMIC_THREAD_FENCE 1)
SET(HAVE_IB_GCC_ATOMIC_COMPARE_EXCHANGE 1)
SET(HAVE_IB_ATOMIC_PTHREAD_T_GCC 1)
SET(HAVE_IB_LINUX_FUTEX 1)
SET(HAVE_GCC_ATOMICS_WITH_ARCH_FLAG 1)
SET(HAVE_FUNC_IN_CXX 1)
SET(HAVE___BUILTIN_FFS 1)
IF(CMAKE_COMPILER_IS_GNUCC)
SET(HAVE_C_FLOATING_POINT_FUSED_MADD 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(HAVE_CXX_FLOATING_POINT_FUSED_MADD 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCC)
SET(HAVE_C_SHIFT_OR_OPTIMIZATION_BUG 1)
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG 1)
ENDIF()
注意:此处的 -DCURSES_LIBRARY=/home/qinb/mysql-5.5-arm/ncurses-5.9/out/lib/libncurses.so 一定要指定到对应的文件,不能只指定到路径,不然没办法正常链接库,本人因为这个问题,编译工作停滞了半天多,具体原因不清楚,是通过查找build/CMakeCache.txt 文件中的内容查找到的,报错如下:
../cmd-line-utils/libedit/libedit.a(term.o): In function `term_echotc’:
term.c:(.text+0×1557): undefined reference to `tputs’
term.c:(.text+0×1580): undefined reference to `tgetstr’
term.c:(.text+0×1676): undefined reference to `tgoto’
term.c:(.text+0x169a): undefined reference to `tputs’
term.c:(.text+0×1761): undefined reference to `tgoto’
term.c:(.text+0×1781): undefined reference to `tputs’
出错问题及解决办法:
报错1:
/home/xgy/tmp/mysql-5.5.30/sql-common/client_plugin.c: In function ‘mysql_client_plugin_init’:
/home/xgy/tmp/mysql-5.5.30/sql-common/client_plugin.c:252:5: error: incompatible type for argument 5 of ‘add_plugin’
/home/xgy/tmp/mysql-5.5.30/sql-common/client_plugin.c:120:1: note: expected ‘va_list’ but argument is of type ‘int’
/home/xgy/tmp/mysql-5.5.30/sql-common/client_plugin.c: In function ‘mysql_client_register_plugin’:
/home/xgy/tmp/mysql-5.5.30/sql-common/client_plugin.c:310:5: error: incompatible type for argument 5 of ‘add_plugin’
解决方案1:
va_list dummy; //增加这一行
add_plugin(&mysql, *builtin, 0, 0, 0); 改为:
add_plugin(&mysql, *builtin, 0, 0,dummy); //也就是把0改为了dummy
将mysql安装目录下的文件和necurses安装目录下的文件打包,放到目标板上,这个需要根据自己的板子上做调整,此处只放运行的方法和主要的几个脚本。
这是交叉编译到网关中的安装说明,mysql版本5.5.62
注意:如果需要修改mysql的运行路径,需要自行根据相应的路径来修改 my.cnf 文件和run-mysql.sh 文件,这两个文件位于arm-mysql-server-5.5.tar.gz压缩包中
拷贝mysql可执行文件和ncurses 库;
启动服务:
#!/bin/sh
export LD_LIBRARY_PATH=/data/ncurses:${LD_LIBRARY_PATH}
执行mysql运行
2.1 拷贝 my.cnf 到 /etc 目录下
2.2 运行脚本 ./run-mysql.sh
my.cnf 文件
[client]
port = 3306
socket = /run/mysql-run/service/mysql.sock
[mysqld]
bind-address = 0.0.0.0
port = 3306
socket = /run/mysql-run/service/mysql.sock
pid-file = /run/mysql-run/service/mysql.pid
character-set-server = utf8
#basedir = /data/mysql
#datadir = /pbox
skip-external-locking
skip-name-resolve
lower_case_table_names = 1
log-bin-trust-function-creators = 1
max_connections = 6000
max_user_connections = 6000
max_connect_errors = 4000
wait_timeout = 86400
interactive_timeout = 86400
table_open_cache = 512
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 32M
#default-storage-engine = InnoDB
#sql_mode="STRICT_ALL_TABLES,NO_AUTO_CREATE_USER"
server-id = 1
log-short-format
log-error = /run/mysql-run/logs/mysql.log
slow_query_log
long_query_time = 2
slow_query_log_file = /run/mysql-run/logs/mysql-slow.log
expire_logs_days = 10
#新增加的
innodb_buffer_pool_size = 8M
#skip-grant-tables=1
# MyISAM Specific options
key_buffer_size = 384M
read_buffer_size = 4M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
myisam_recover
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
default-character-set = utf8
no-auto-rehash
socket = /run/mysql-run/service/mysql.sock
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
run-mysql.sh 文件
#!/bin/bash
MYSQL_BASE=/data/mysql
echo "Create file"
if [ ! -d "/run/mysql-run" ];then
mkdir /run/mysql-run
fi
if [ ! -d "/run/mysql-run/service" ];then
mkdir /run/mysql-run/service
fi
if [ ! -d "/run/mysql-run/service/data" ];then
mkdir /run/mysql-run/service/data
fi
if [ ! -f "/run/mysql-run/mysql.sock" ];then
touch /run/mysql-run/mysql.sock
fi
if [ ! -f "/run/mysql-run/service/mysql.sock" ];then
touch /run/mysql-run/service/mysql.sock
fi
if [ ! -f "/run/mysql-run/service/mysql.pid" ];then
touch /run/mysql-run/service/mysql.pid
fi
if [ ! -f "/run/mysql-run/service/data/mysql.sock" ];then
touch /run/mysql-run/service/data/mysql.sock
fi
echo "copy mysqld config file to /etc/ "
if [ ! -f "/etc/my.cnf" ];then
cp my.cnf /etc/my.cnf
fi
echo "Create link to /usr/bin"
ln -s ${MYSQL_BASE}/bin/mysqld /usr/bin/mysqld
ln -s ${MYSQL_BASE}/bin/mysql /usr/bin/mysql
ln -s ${MYSQL_BASE}/bin/my_print_defaults /usr/bin/my_print_defaults
ln -s ${MYSQL_BASE}/bin/mysqladmin /usr/bin/mysqladmin
ln -s ${MYSQL_BASE}/bin/mysqldump /usr/bin/mysqldump
echo "Setup the mysql-5.5 ....."
echo "Initailize the data directory and create the MySQL grant tables"
${MYSQL_BASE}/bin/mysqld --user=root --basedir=${MYSQL_BASE} --datadir=${MYSQL_BASE}/data &
echo "[Done]"
exit 0;
注意:配置文件可以按照需求去改,含义在网上查找,此处不列
mysql> use mysql;
Database changed
mysql>
mysql> update user set password=password(‘123456’) where user=‘root’ and host=‘localhost’;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql>
mysql> grant all privileges on . to ‘root’@‘%’ identified by ‘123456’ with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
遇到问题
报错1:
220807 15:11:33 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
原因1:
一般为 mysql 重新安装后数据目录不一致造成的
解决方案1:
进入mysql安装目录cd /usr/local/mysql/scripts/
./mysql_install_db --user=root --basedir=/data/mysql --datadir=/data/mysql/data &
注意:上面这条命令的最后的 & 一定不能缺少
报错2:
MySQL Plugin ‘InnoDB’ init function returned error.
解决2:
只要删除MySQL目录下的ib_logfile0和ib_logfile1两个文件,就可以解决问题了。
报错3:
2019-01-16 10:22:48 39795 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2019-01-16 10:22:48 39795 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
解决3:
修改my.cnf 中 innodb_buffer_pool_size的大小为8M或者64M
innodb_buffer_pool_size = 8M (安装MySQL5.6到小于1G内存服务器上,启动MySQL会失败,报内存分配失败的错误,此时,需要修改my.cnf的内存大小从标准128M设置到8M或者64M)