MySQL安装 MySQL的几个常用安装包:rpm(无法定义安装路径跟二进制区别)、源码(Cmake)、二进制免编译(编译过好的保存在一个目录下在打包压缩)没有特殊要求可以使用这种方法 cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql cd /usr/local/mysql useradd mysql mkdir /data/ 存放mysql数据 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 初始化 cp support-files/my-default.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld vi /etc/init.d/mysqld 定义basedir和datadir basedir=/usr/local/mysql datadir=/data/mysql

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# service mysqld start

[root@lsx-001 mysql]# netstat -lnpt

Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1788/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1111/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1788/master
tcp6 0 0 :::3306 :::* LISTEN 20133/mysqld

如果没有/etc/init.d/启动文件可采用的启动方式如下图:

停止的方式:killall mysqld killall 先停止当前的写读操作,把还没有写入磁盘的数据写入磁盘,在杀死进程

问题!! [root@lsx-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper 解决办法安装 [root@lsx-02 mysql]# yum install -y autoconf

[root@lsx-001 mysql]# yum list|grep -i perl |grep -i dumper perl-Data-Dumper.x86_64 2.145-3.el7 base

Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

[root@lsx-02 mysql]# yum list |grep 'libaio' [root@lsx-02 mysql]# yum install -y libaio-devel.x86_64

3.启动报错Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. ./usr/local/mysql/bin/mysqld_safe: line 178: 2830 Killed nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid < /dev/null > /dev/null 2>&1 ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid). 解决办法: 1.cd /usr/local/mysql(进入mysql安装目录) 2.chown -R mysql.mysql . 3.su - mysql 4.cd /usr/local/mysql 5.scripts/mysql_install_db

4.登录mysql mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决办法: less /etc/my.cnf|grep sock #socket = ..... vi /etc/my.cnf socket = /tmp/mysql.sock  #添加该行 重启

5.启动错误后面提示什么文件没找到ERROR! MySQL server PID file could not be found! 就创建一个。比如: touch /data/mysql/localhost.localdomain.pid