首页 > 代码库 > Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS from Source
Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS from Source
This post documents the steps of installing MySQL from source code, and the resolutions to serveral issues in installing. The steps here are specific to 64-bit Ubuntu 14.04.1 LTS, and MySQL source code is 5.7.5-m15. But I think most of them can also work on your system.
Download MySQL source code
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.5-m15.tar.gz
Install GCC/G++/Make/CMake
If your system has not installed gcc/g++/make/cmake yet, please install them first. The following commands should be able to get your system installed correct and proper versions.
apt-get install updateapt-get install gccapt-get install g++apt-get install makeapt-get install cmake cmake-gui
Other dependencies
If the system prompts "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." when you execute "cmake .", please run apt-get to install the library.
apt-get install libncurses5-dev
If the error "Bison executable not found in PATH.", please run the command below.
apt-get install bison
Install MySQL
#groupadd mysqluseradd -r -g mysql mysql#tar zxvf mysql-VERSION.tar.gzcd mysql-VERSION#cmake . -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost -DENABLE_DOWNLOADS=1makemake install#cd /usr/local/mysqlchown -R mysql .chgrp -R mysql .# from 5.7.5, the --datadir option is mandatory.bin/mysql_install_db --datadir=/usr/local/mysql/data#chown -R root .chown -R mysql data # Open the MySQL config filevi /etc/mysql/my.cnf
Change the default values of basedir, datadir, and lc-message-dir to the following values.
basedir = /usr/local/mysqldatadir = /usr/local/mysql/datalc-messages-dir = /usr/local/mysql/share # this setting will avoid the error "[ERROR] Can‘t find error-message file ‘/usr/share/mysql/errmsg.sys‘".
If your MySQL log is under /var/log/mysql, please execute the following commands. The commands will prevent the error "touch: cannot touch /var/log/mysql/error.log: No such file or directory" from happening when you run "bin/mysqld_safe --user=mysql &".
mkdir /var/log/mysqlchown -R mysql:mysql /var/log/mysql
Run mysqld_safe to try to start mysql. Don‘t omit the ‘&‘. :-)
bin/mysqld_safe --user=mysql &
If you see the following errors in /var/log/mysql/error.log, open /etc/mysql/my.cnf and edit the variables like below.
[ERROR] unknown variable ‘key_buffer=16M‘
vi /etc/mysql/my.cnf, change ‘key_buffer=16M‘ to ‘key_buffer_size=16M‘.
[ERROR] unknown variable ‘myisam-recover=BACKUP‘
Comments out this line ‘myisam-recover=BACKUP‘ in /etc/mysql/my.cnf with a ‘#‘.
Reset password for root
First, you need login mysql server with the random password generated by mysql_install_db. You can find the password in the file /root/.mysql_secret.
/usr/local/mysql/bin/mysql -u root -p
Then, use Set Password statement to set new password.
mysql> set password = password(‘your password‘);
Add MySQL Server executables to system PATH
Create a file mysql.sh under /etc/profile.d/ directory,
touch /etc/profile.d/mysql.shvi /etc/profile.d/mysql.sh
and add the following lines to the file.
#!/bin/bashif ! echo ${PATH} | /bin/grep -q /usr/local/mysql/bin ; thenPATH=/usr/local/mysql/bin:${PATH}fi
Use the following command to add the path to the current shell.
source /etc/profile.d/mysql.sh
Use echo $PATH to check if the script works. "/usr/local/mysql/bin" should be in the output.
echo $PATH
Add MySQL Server libraries to the shared library cache
touch /etc/ld.so.conf.d/mysql.confecho "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.confldconfig
Set MySQL Server service
cp support-files/mysql.server /etc/init.d/mysqlservice mysql start
Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS from Source