编译安装mysql以及启动mysql
编译安装mysql
1、编译前的依赖安装:
yum install ncurses-devel libaio-devel gcc cmake
2、创建mysql用户:
[root@CentOs ~]# useradd -s /sbin/nologin -M mysql
[root@CentOs ~]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)
[root@CentOs ~]#
3、获取mysql的源代码:
https://mirrors.sohu.com/mysql/MySQL-5.6/
[root@CentOs tools]# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz
4、解压缩,安装mysql
[root@CentOs tools]#tar -zxvf mysql-5.6.40.tar.gz
[root@CentOs tools]# ls
mysql-5.6.40 mysql-5.6.40.tar.gz
[root@CentOs tools]#
5、执行cmake,生成Makefile,用于编译安装
[root@CentOs mysql-5.6.40]#
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \
-DMYSQL_DATADIR=/application/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
6、cmake编译参数设置完毕之后,就会自动生成Makefile文件,可以执行 make 和make install了
[root@CentOs mysql-5.6.40]# make
[root@CentOs mysql-5.6.40]# make && make install
7、验证mysql安装
8、创建软链接:
[root@CentOs bin]# ln -s /application/mysql-5.6.40/ /application/mysql
[root@CentOs bin]#
mysql数据初始化操作
1、执行如下初始化命令:
[root@CentOs scripts]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
要保证出现两个ok才可以!
以及看到如下文件表示初始化正确!
2、启动mysql
使用mysql初始化自动生成的管理脚本
[root@CentOs mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@CentOs mysql]# chmod 700 /etc/init.d/mysqld
[root@CentOs mysql]#
拷贝配置文件
[root@CentOs mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@CentOs mysql]#
开始启动mysql
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql-5.6.40/data/localhost.localdomain.err'.
220613 23:03:23 mysqld_safe Directory '/application/mysql-5.6.40/tmp' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/application/mysql-5.6.40/data/localhost.localdomain.pid).
[root@localhost mysql]#
此处会报错,是因为缺少tmp目录,创建即可
[root@CentOs mysql]# mkdir -p /application/mysql/tmp
[[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/application/mysql-5.6.40/data/localhost.localdomain.err'.
.. ERROR! The server quit without updating PID file (/application/mysql-5.6.40/data/localhost.localdomain.pid).
[root@localhost mysql]#
此处是权限出现问题
如何解决此处报错?
[root@CentOs mysql]# chown -R mysql.mysql /application/mysql/
再次尝试启动mysql
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost mysql]# netstat -tunlp|grep mysql
tcp6 0 0 :::3306 :::* LISTEN 89937/mysqld
[root@localhost mysql]#