2014-07-14
在http://dev.mysql.com/downloads/mysql/下载源码包。我下载的是mysql-5.6.19.tar.gz
。
我的目标是将其安装在当前目录(mysql-5.6.19.tar.gz
所在目录)下的mysql5.6
目录中。
准备工作
$ sudo apt-get install cmake
$ sudo apt-get install bison
$ sudo apt-get install libncurses5-dev
定位libncurses.so:
$ locate libncurses.so
/lib/x86_64-linux-gnu/libncurses.so.5
/lib/x86_64-linux-gnu/libncurses.so.5.9
添加用户
$ sudo groupadd mysql
$ sudo useradd -r -g mysql mysql
安装
解压mysql-5.6.19.tar.gz
。
$ tar -xvf mysql-5.6.19.tar.gz #解压到目录mysql-5.6.19中
创建安装目录:
$ mkdir mysql5.6
进入mysql-5.6.19
:
$ cd mysql-5.6.19
编译安装:
执行下面的命令:
cmake -DCMAKE_INSTALL_PREFIX=../mysql5.6 -DMYSQL_DATADIR=../mysql5.6/data -DSYSCONFDIR=../mysql5.6 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DCURSES_LIBRARY=/lib/x86_64-linux-gnu/libncurses.so.5 -DCURSES_INCLUDE_PATH=/usr/include
或者下面这样(更易读):
$ cmake \
-DCMAKE_INSTALL_PREFIX=../mysql5.6 \
-DMYSQL_DATADIR=../mysql5.6/data \
-DSYSCONFDIR=../mysql5.6 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DCURSES_LIBRARY=/lib/x86_64-linux-gnu/libncurses.so.5 \
-DCURSES_INCLUDE_PATH=/usr/include
$ make
$ make install
参数含义以及更多参数,可以参考2.8.4 MySQL Source-Configuration Options。
后续处理
$ cd ../mysql5.6
$ sudo chown -R mysql:mysql .
$ sudo chown -R root:mysql .
$ sudo scripts/mysql_install_db --user=mysql
另外,需要将bin/
目录加入PATH。
添加service文件
$ sudo cp support-files/mysql.server /etc/init.d/mysql.server
启动mysql
$ sudo bin/mysqld_safe --user=mysql &
或者:
$ sudo service mysql.server start
查看mysql是否启动
$ netstat -tnl|grep 3306
或者
$ ps -ef | grep 'mysql'
设置root密码
在一个终端中,使用下面的命令启动mysql服务:
$ sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
启动mysql后,
$ mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
问题1
错误:
bash >> mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.19 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Segmentation fault
解决方法: 在cmd-line-utils/libedit/terminal.c
中找到
terminal_set(EditLine *el, const char *term)
{
int i;
char buf[TC_BUFSIZE];
char *area;
const struct termcapstr *t;
sigset_t oset, nset;
int lins, cols;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
area = buf;
将其改成:
terminal_set(EditLine *el, const char *term)
{
int i;
//char buf[TC_BUFSIZE];
char *area;
const struct termcapstr *t;
sigset_t oset, nset;
int lins, cols;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
//area = buf;
area = NULL;
重新编译安装即可。
问题2
错误:
bash >> sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
sudo: mysqld_safe: command not found
command not found when using sudo给出的原因是:
$PATH is evaluated by your shell, so your check doesn't work as you expect it to.
/etc/sudoers is configured to replace your PATH with a default one.
sudo does not load a login shell environment before executing the command, so the default PATH from /etc/sudoers is used. su - does open a login shell, which involves loading /etc/profile. See man bash, section INVOCATION.
解决方法是,打开/etc/sudoers,找到:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
把mysql下bin目录的绝对路径添加进去。
问题3
开始时,安装完后,我是使用下面的方式做的后续处理:
$ cd ../mysql5.6
$ sudo scripts/mysql_install_db --user=mysql
$ sudo chown -R mysql:mysql .
$ sudo chown -R root:mysql .
不过启动的时候报错:
mysql The server quit without updating PID file
解决方法是使用下面的顺序进行后续处理:
$ cd ../mysql5.6
$ sudo chown -R mysql:mysql .
$ sudo chown -R root:mysql .
$ sudo scripts/mysql_install_db --user=mysql
参考资料
command not found when using sudo
MySQL安装完成后首次登陆 报错 Segmentation fault
ubuntu下mysql无法启动Couldn't find MySQL server (/usr/bin/mysqld_safe)”
2.17.3 MySQL Source-Configuration Options
2.8.2 Installing MySQL Using a Standard Source Distribution
Linux源码安装mysql 5.6.12 (cmake编译)
Linux源码安装mysql 5.5.13 (cmake编译)
解决Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
Where to set environment variables to work with sudo?
mysql Access denied for user root@localhost错误解决方法总结