[linux]linux下安装mysql
1、安装g++
$sudo apt-get install build-essential
注:此命令会同时安装gcc和make
2、安装cmake
$sudo apt-get install cmake
3、安装mysql
进入mysql文件所在目录(cd)
$unzip mysql-5.6.4-m7.tar\(1\).zip
$tar -zxvf mysql-5.6.4-m7.tar.gz
进入mysql-5.6.4-m7
$cd mysql-5.6.4-m7
$groupadd mysql //所以在这里我们要建一个msyql的用户和组
$useradd -g mysql mysql -s /usr/sbin/nologin
$mkdir /usr/local/mysql //创建目录
$mkdir /usr/local/mysql/data
$cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql && make && make install
此时可以会出错,提示缺少ncurses library之类的,输入以下命令来安装
$sudo apt-get install libncurses5-dev
然后删除目录中的CMakeCache.txt
$sudo rm CMakeCache.txt
继续操作输入cmake -DCMAKE....这条命令就安装成功了
4、配置mysql
进入mysql的安装目录/usr/local/mysql下:
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql //初始化mysql数据库
cp support-files/my-medium.cnf /usr/local/mysql/my.cnf //copy配置文件
chown -R mysql:mysql /usr/local/mysql //更改权限
vi /usr/local/mysql/my.cnf //加上以下内容
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
启动mysql bin/mysqld_safe --user=mysql & 或使用下列命令把mysql添加为系统服务。
cd /usr/local/mysql/support-files/
cp ./mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start