安装mysql需要的编译工具:
yum -y install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel make bison-devel autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel*
下载mysql:选择source code / generic linux
tar -zxvf mysql文件
cd mysql文件
执行以下命令
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
结束后执行:
make && make install 编译并安装
复制配置文件
cp support-files/my-medium.cnf /etc/my.cnf
初始化数据库:
cd /usr/local/mysql/bin
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data
--basedir和--datadir根据自己的安装路径配置
启动mysql数据库
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld #增加可执行权限
mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log
/etc/init.d/mysqld start 或 service mysqld start
设置用户密码
mysqladmin -u root password 'yourpassword'
至此,即可使用命令:mysql -u root -p password 进入数据库