mysql安装和配置
操作系统:centos7
mysql版本:mysql5.5
源码编译安装mysql
1)获取安装包:
https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.61.tar.gz
2)创建mysql的用户和组:
[root@10e4e9b5fd22 mysql-5.5.61]# groupadd mysql
[root@10e4e9b5fd22 mysql-5.5.61]# useradd -r -g mysql -s /bin/false mysql
[root@10e4e9b5fd22 mysql-5.5.61]# passwd mysql
3)创建mysql相关目录:
[root@10e4e9b5fd22 mysql-5.5.61]# mkdir -p /data/mysql #创建mysql根目录
[root@10e4e9b5fd22 mysql-5.5.61]# mkdir -p /data/mysql/data #创建mysql数据文件目录
[root@10e4e9b5fd22 mysql-5.5.61]# chown -R mysql:mysql /data/mysql #授予mysql目录权限
4)软件依赖安装:
yum install cmake;
yum install gcc;
yum install gcc-c++;
yum install ncurses-devel;
yum install perl;
5)源码编译安装mysql:
[root@10e4e9b5fd22 upload]# tar -zxvf mysql-5.5.61.tar.gz
[root@fb59a966e180 upload]# cd mysql-5.5.61
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/data/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
[root@10e4e9b5fd22 upload] make
[root@10e4e9b5fd22 upload] make install
6)配置mysql和启动mysql:
创建mysql的配置文件
cp /data/mysql/support-files/my-medium.cnf /etc/my.cnf
创建mysql的启动脚本
cp /data/mysql/support-files/mysql.server /etc/init.d/mysql
初始化数据库字典
[root@fb59a966e180 mysql]# cd /data/mysql
[root@fb59a966e180 mysql]# ./scripts/mysql_install_db --user=mysql
启动mysql并且更改mysql的用户名和密码
[root@fb59a966e180 mysql]# bin/mysqld_safe --user=mysql &
[root@fb59a966e180 mysql]# ./bin/mysqladmin -uroot password root
开启mysql远程登录
mysql> flush privileges;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;