Centos安装MySQL
更多
卸载原有相关包
[root@yuntao ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
安装编译代码需要的包
[root@yuntao ~]# yum -y install wget make cmake gcc gcc-c++ cmake bison-devel ncurses-devel
下载 wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
解压
[root@yuntao ~]#tar xf mysql-5.6.25.tar.gz
[root@yuntao ~]#cd mysql-5.6.25.tar.gz
编译配置
[root@yuntao ~]#
cmake \
-DCMAKE_INSTALL_PREFIX=/u01/mysql \
-DMYSQL_DATADIR=/u01/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.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
编译安装
[root@yuntao ~]#make && make install
创建用户
[root@yuntao ~]#groupadd mysql
[root@yuntao ~]#useradd -g mysql mysql
修改/u01/mysql权限
[root@yuntao ~]#chown -R mysql:mysql /u01/mysql
配置环境变量
修改/etc/profile文件,在文件末尾添加
PATH=/u01/mysql/bin:$PATH
export PATH
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表
[root@yuntao ~]#
scripts/mysql_install_db --basedir=/u01/mysql --datadir=/u01/mysql/data --user=mysql
启动MySQL
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp support-files/mysql.server /etc/init.d/mysqld
[root@yuntao ~]#chkconfig mysqld on
//设置为开机自启动
[root@yuntao ~]#service mysqld start --启动MySQL
重启
[root@yuntao ~]#service mysqld restart
连接
[root@yuntao ~]# mysql
-uroot -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25 Source distribution
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
更多
卸载原有相关包
[root@yuntao ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
安装编译代码需要的包
[root@yuntao ~]# yum -y install wget make cmake gcc gcc-c++ cmake bison-devel ncurses-devel
下载 wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
解压
[root@yuntao ~]#tar xf mysql-5.6.25.tar.gz
[root@yuntao ~]#cd mysql-5.6.25.tar.gz
编译配置
[root@yuntao ~]#
cmake \
-DCMAKE_INSTALL_PREFIX=/u01/mysql \
-DMYSQL_DATADIR=/u01/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.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
编译安装
[root@yuntao ~]#make && make install
创建用户
[root@yuntao ~]#groupadd mysql
[root@yuntao ~]#useradd -g mysql mysql
修改/u01/mysql权限
[root@yuntao ~]#chown -R mysql:mysql /u01/mysql
配置环境变量
修改/etc/profile文件,在文件末尾添加
PATH=/u01/mysql/bin:$PATH
export PATH
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表
[root@yuntao ~]#
scripts/mysql_install_db --basedir=/u01/mysql --datadir=/u01/mysql/data --user=mysql
启动MySQL
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
cp support-files/mysql.server /etc/init.d/mysqld
[root@yuntao ~]#chkconfig mysqld on
//设置为开机自启动
[root@yuntao ~]#service mysqld start --启动MySQL
重启
[root@yuntao ~]#service mysqld restart
连接
[root@yuntao ~]# mysql
-uroot -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25 Source distribution
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>