centos 6.10源码安装mysql5.5.62实验

查看系统版本

[root@ABC ~]# cat /etc/redhat-release

CentOS release 6.10 (Final)

下载mysql5.5.62源码包,解压后安装

tar –zxf mysql-5.5.62.tar.gz -C /usr/local/src

根据提示安装必要的依赖库文件

yum install -y gcc gcc-c++ ncurses-devel git cmake

预编译规划

Mysql软件安装目录/usr/local/mysql;mysql数据目录为/usr/local/mysql/data;

Mysql错误日志文件保存目录为/var/log/mysql/error.log,创建相应目录和用户并赋权

groupadd mysql&&useradd –r –g mysql –s /sbin/false

mkdir –p /usr/local/mysql/data&&chown –R mysql:mysql /usr/local/mysql

mkdir /var/log/mysql&&chown –R mysql:mysql /var/log/mysql

进入解压包目录,使用cmake预编译

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data/ -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1

编译安装

make –j 4&& make install –j 4

进入安装目录执行操作

cd /usr/local/mysql

拷贝mysql服务脚本文件到系统目录

cp support-files/mysql.server /ect/init.d/mysqld

设置mysqld服务为开机自启动

chkconfig - -level 3 mysqld on

chkconfig - -list mysqld

启动mysql服务

service mysqld start

启动报错,无法正常启动

安装完5.5.62的mysql后,必需要先执行mysql_install_db才能执行后续操作

[root@ABC mysql]#/usr/local/mysql/ scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h 主机名 password 'new-password'

Alternatively you can run:

/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

启动mysql服务

[root@ABC mysql]# service mysqld start

Starting MySQL SUCCESS!

修改环境变量,将mysql命令添加到系统中

PATH=$PATH:/usr/local/mysql/bin

要想使命令永久生效,需要将该命令添加到$HOME/.bashrc_profile文件末尾即可,

使用source $HOME/.bashrc_profile 让命令生效

安全初始化mysql

[root@ABC ~]# mysql_secure_installation

登陆mysql

[root@ABC ~]# mysql –u root –p password

查看端口和状态

[root@ABC mysql]# netstat -ntulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23441/mysqld

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2195/sshd

tcp 0 0 :::80 :::* LISTEN 1744/httpd

tcp 0 0 :::22 :::* LISTEN 2195/sshd

udp 0 0 0.0.0.0:68 0.0.0.0:* 1231/dhclient

[root@ABC mysql]# ps -ef | grep mysql

root 23145 1991 0 18:34 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe

mysql 23441 23145 0 18:34 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=ABC.pid --socket=/usr/local/mysql/mysql.sock --port=3306

root 23872 1991 0 19:36 pts/0 00:00:00 grep mysql

重启测试

[root@b mysql]# service mysqld restart

ERROR! MySQL server PID file could not be found!

无法启动,提示server PID无法找到关闭selinux防火墙并重启测试

[root@b mysql]# vim /etc/selinux/config

[root@b mysql]# reboot

[root@ABC ~]# service mysqld restart

Shutting down MySQL. SUCCESS!

Starting MySQL.. SUCCESS!

至此数据库安装成功。