mysql的搭建
创建程序用户
root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -s /sbin/nologin -g mysql -M mysql [root@localhost ~]# tail -1 /etc/passwd mysql:x:501:501::/home/mysql:/sbin/nologin [root@localhost ~]# id mysql uid=501(mysql) gid=501(mysql) groups=501(mysql)
mysql的源码包安装
MySQL的原理和步骤 1准备工作。只要服务器没有MySQL的server就可以然后用yum安装ncurses-devel 支持包,用编译按cmake ./configure && gmake && gmake install
2原编码,及安装,需要增加用户mysql
安装mysql,源码的命令cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
3.安装后需要优化操作,修改mysql的属主与属组 /bin/cp support-files/my-medium.cnf /etc/my.cnf /bin/cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
报错2002,的解决方法 [root@r710-1 /]# mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) [root@r710-1 /]# vi /etc/my.cnf ##########添加如下内容: [client] socket=/var/lib/mysql/mysql.sock ##########保存退出后, ##########重启mysql [root@r710-1 /]# service mysqld restart Shutting down MySQL. [ OK ] Starting MySQL. [ OK ]
二进制包安装mysql
)获取MySQL二进制软件包
百度云盘:http://pan.baidu.com/s/1hrBCzsC提取码:4yjf
解压缩二进制包
root@localhost ~]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# mv mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32 [root@localhost local]# ln -s mysql-5.5.32 mysql [root@localhost local]# ls bin games lib libexec mysql-5.5.32 nginx-1.10.2 share etc include lib64 mysql nginx sbin src [root@localhost local]# cd /usr/local/mysql [root@localhost mysql]# ls bin data include lib mysql-test scripts sql-bench COPYING docs INSTALL-BINARY man README share support-files #提示: 二进制安装包,仅需要解压就可以了,不需要执行cmake/configure,make,make install等过程
初始化二进制mysql
root@localhost ~]# mkdir -p /usr/local/mysql/data #建立MySQL数据文件目录 [root@localhost ~]# chown -R mysql.mysql /usr/local/mysql #授权mysql用户管理MySQL的安装目录 [root@localhost ~]# yum -y install libaio #光盘源安装依赖包,否则下一步的编译会报错 [root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql #初始化MySQL数据库文件,会有很多信息提示,如果没有ERROR级别的错误,会有两个OK的字样,表示初始化成功,否则就要解决初始化的问题
错误排除
错误示例1: usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared ob #错误原因是没有libaio函数库的支持。需要 yum -y install libaio 错误示例2: WARNING:The host'mysql'could not be looked up with resolveip #需要修改主机名解析,使其和uname -n一样,修改后的结果如下: [root@localhost ~] # grep `uname -n` /etc/hosts 错误示例3: ERROR:1004Can't create file '/tmp/#sql300e_1_o.frm'(errno:13) #原因是/tmp目录的权限有问题。 解决办法为处理/tmp目录,如下: [root@localhost ~]# ls -ld /tmp drwxrwxrwt. 3 root root 4096 Jul 14 07:56 /tmp [root@localhost ~]# chmod -R 777 /tmp/ 此故障必须解除,否则,后面会出现登陆不了数据库等问题。
配置启动脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld #拷贝MySQL启动脚本到MySQL的命令路径 [root@localhost mysql]# chmod +x /etc/init.d/mysqld #使脚本可执行 (2)MySQL二进制默认安装路径是/usr/local/mysql,启动脚本里是/usr/local/mysql。如果安装路径不同,那么脚本里路径等都需要替换 (3)启动MySQL数据库,命令如下: [root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL.. SUCCESS!
提取码:4yjf