导读 | 一般中小型网站的开发都选择 MySQL 作为网站数据库,由于其社区版的性能卓越,搭配 PHP 、Linux和 Apache 可组成良好的开发环境,经过多年的web技术发展,在业内被广泛使用的一种web服务器解决方案之一。但是mysql源码包编译时间过长,今天将采用二进制包方式安装mysql,并进行优化配置,希望对广大读者有借鉴意义。 |
1.安装之前,先创建mysql用户
[[email protected]_nfs ~]# useradd mysql -s /sbin/nologin -M [[email protected]_nfs ~]# id mysql uid=500(mysql) gid=500(mysql) groups=500(mysql)
2.软件包的下载及解压
[[email protected]_nfs ~]# mkdir /home/chenfan/tools -p [[email protected]_nfs ~]# cd /home/chenfan/tools 在http://dev.mysql.com/downloads/mysql/官网上下载mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# ls mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# ls mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs local]# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql-5.5.32 ###免编译安装 [[email protected]_nfs local]# cd /usr/local [[email protected]_nfs local]# ln -s mysql-5.5.32 mysql ###此处的软链接为了版本升级提供了便利
3.初始化数据库
[[email protected]_nfs local]# mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql ###此处如果初始化发生错误,删除data目录下的内容,rm -fr mysql/data/*,重新初始化。
4.生成MySQL配置文件
[[email protected]_nfs local]# cd mysql [[email protected]_nfs mysql]# cp support-files/my-small.cnf /etc/my.cnf
5.授权管理文件
[[email protected]_nfs ~]# chown -R mysql:mysql /usr/local/mysql/ [[email protected]_nfs ~]# ls -ld /usr/local/mysql/ drwxr-xr-x. 13 mysql mysql 4096 Jun 24 17:21 /usr/local/mysql/
6.设置科学的启动方式
[[email protected]_nfs mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected]_nfs mysql]# chmod +x /etc/init.d/mysqld [[email protected]_nfs mysql]# /etc/init.d/mysqld start Starting MySQL... SUCCESS! [[email protected]_nfs mysql]# chkconfig --add mysqld [[email protected]_nfs mysql]# chkconfig mysqld on [[email protected]_nfs mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ### 设置开机自启动mysql
7.配置MySQL环境变量
[[email protected]_nfs mysql]# echo ‘PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile [[email protected]_nfs mysql]# source /etc/profile [[email protected]_nfs mysql]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin ###此处PATH路径的设置为了后续mysql命令的使用
8.mysql登陆与密码设置
[[email protected]_nfs mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.32 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> [[email protected]_nfs mysql]# mysqladmin -uroot password ‘chenfan‘ ###密码的设置 [[email protected]_nfs mysql]# mysql -uroot -p Enter password: chenfan ###交互式登陆 ###至此完成MySQL的全部初始安装与配置
导读 | 一般中小型网站的开发都选择 MySQL 作为网站数据库,由于其社区版的性能卓越,搭配 PHP 、Linux和 Apache 可组成良好的开发环境,经过多年的web技术发展,在业内被广泛使用的一种web服务器解决方案之一。但是mysql源码包编译时间过长,今天将采用二进制包方式安装mysql,并进行优化配置,希望对广大读者有借鉴意义。 |
1.安装之前,先创建mysql用户
[[email protected]_nfs ~]# useradd mysql -s /sbin/nologin -M [[email protected]_nfs ~]# id mysql uid=500(mysql) gid=500(mysql) groups=500(mysql)
2.软件包的下载及解压
[[email protected]_nfs ~]# mkdir /home/chenfan/tools -p [[email protected]_nfs ~]# cd /home/chenfan/tools 在http://dev.mysql.com/downloads/mysql/官网上下载mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# ls mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs tools]# ls mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32-linux2.6-x86_64.tar.gz [[email protected]_nfs local]# mv mysql-5.5.32-linux2.6-x86_64 /usr/local/mysql-5.5.32 ###免编译安装 [[email protected]_nfs local]# cd /usr/local [[email protected]_nfs local]# ln -s mysql-5.5.32 mysql ###此处的软链接为了版本升级提供了便利
3.初始化数据库
[[email protected]_nfs local]# mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql ###此处如果初始化发生错误,删除data目录下的内容,rm -fr mysql/data/*,重新初始化。
4.生成MySQL配置文件
[[email protected]_nfs local]# cd mysql [[email protected]_nfs mysql]# cp support-files/my-small.cnf /etc/my.cnf
5.授权管理文件
[[email protected]_nfs ~]# chown -R mysql:mysql /usr/local/mysql/ [[email protected]_nfs ~]# ls -ld /usr/local/mysql/ drwxr-xr-x. 13 mysql mysql 4096 Jun 24 17:21 /usr/local/mysql/
6.设置科学的启动方式
[[email protected]_nfs mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected]_nfs mysql]# chmod +x /etc/init.d/mysqld [[email protected]_nfs mysql]# /etc/init.d/mysqld start Starting MySQL... SUCCESS! [[email protected]_nfs mysql]# chkconfig --add mysqld [[email protected]_nfs mysql]# chkconfig mysqld on [[email protected]_nfs mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ### 设置开机自启动mysql
7.配置MySQL环境变量
[[email protected]_nfs mysql]# echo ‘PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile [[email protected]_nfs mysql]# source /etc/profile [[email protected]_nfs mysql]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin ###此处PATH路径的设置为了后续mysql命令的使用
8.mysql登陆与密码设置
[[email protected]_nfs mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.32 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> [[email protected]_nfs mysql]# mysqladmin -uroot password ‘chenfan‘ ###密码的设置 [[email protected]_nfs mysql]# mysql -uroot -p Enter password: chenfan ###交互式登陆 ###至此完成MySQL的全部初始安装与配置
时间: 2024-10-23 20:55:26