Linux安装MySQL的两种办法
2. 安置办法:
安置MySQL主要有两种办法:一种是通过源码自行编译安置,这种适合高级会员定制MySQL的特性,这里不做说明;另一种是通过编译过的二进制文件停止安置。二进制文件安置的办法又分为两种:一种是不针对特定平台的通用安置办法,使用的二进制文件是后缀为.tar.gz的紧缩文件;第二种是使用RPM或其他包停止安置,这种安置进程会主动完成系统的相关配置,所以比力利便。
3. 下载安置包:
a. 官方下载地址:
http://dev.mysql.com/downloads/mysql/#downloads
或镜像文件下载:
http://dev.mysql.com/downloads/mirrors.html
2. 下载文件(按照操纵系统选中响应的公布版本):
a. 通用安置办法
mysql-5.5.29-linux2.6-x86_64.tar.gz
b. RPM安置办法:
MySQL-server-5.5.29-2.el6.x86_64.rpm MySQL-client-5.5.29-2.el6.x86_64.rpm
4. 通用安置步骤
a. 检查可否已安置,grep的-i选项表示匹配时忽略大小写
[root@localhost JavaEE]#rpm -qa|grep -i mysql mysql-libs-5.1.61-4.el6.x86_64 *可见已经安置了库文件,应当先卸载,不然会显现覆盖错误。留意卸:载时使用了--nodeps选项,忽略了依靠关系: [root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps
b. 增加mysql组和mysql会员,用于设定mysql安置名目文件所有者和所属组。
[root@localhost JavaEE]#groupadd mysql [root@localhost JavaEE]#useradd -r -g mysql mysql *useradd -r参数表示mysql会员是系统会员,不成用于登录系统。
c. 将二进制文件解压到指定的安置名目,我们这里指定为/usr/local
[root@localhost ~]# cd/usr/local/ [root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz *加压后在/usr/local/生成理解压后的文件夹mysql-5.5.29-linux2.6-x86_64,这名字太长,我们为它创立一个符号链接mysql,利便输入。 [root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql
d. /usr/local/mysql/下的名目构造
Directory | Contents of Directory |
bin | Client programs and the mysqld server |
data | Log files, databases |
docs | Manual in Info format |
man | Unix manual pages |
include | Include (header) files |
lib | Libraries |
scripts | mysql_install_db |
share | Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench | Benchmarks |
e. 进入mysql文件夹,也就是mysql所在的名目,并更换所属的组和会员。
[root@localhost local]#cd mysql [root@localhost mysql]#chown -R mysql . [root@localhost mysql]#chgrp -R mysql .
f. 施行mysql_install_db足本,对mysql中的data名目停止初始化并创立一些系统表格。留意mysql效劳进程mysqld运转时会拜访data名目,所以必需由启动mysqld进程的会员(就是我们此前设定的mysql会员)施行这个足本,或者用root施行,但是加上参数--user=mysql。
[root@localhost mysql]scripts/mysql_install_db --user=mysql *假如mysql的安置名目(解压名目)不是/usr/local/mysql,那么还必需指定名目参数,如 [root@localhost mysql]scripts/mysql_install_db --user=mysql \ --basedir=/opt/mysql/mysql \ --datadir=/opt/mysql/mysql/data*将mysql/名目下除了data/名目的所有文件,改回root会员所有,mysql会员只需作为mysql/data/名目下所有文件的所有者。 [root@localhost mysql]chown -R root . [root@localhost mysql]chown -R mysql data
g. 复制配置文件
[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf
h. 将mysqld效劳参加开机自启动项。
*第一需要将scripts/mysql.server效劳足本复制到/etc/init.d/,并重命名为mysqld。 [root@localhostmysql] cp support-files/mysql.server /etc/init.d/ mysqld *通过chkconfig命令将mysqld效劳参加到自启动效劳项中。 [root@localhost mysql]#chkconfig --add mysqld *留意效劳名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。 *查看可否增加成功 [root@localhost mysql]#chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off i. 重新启动系统,mysqld就会主动启动了。 *检查可否启动 [root@localhost mysql]#netstat -anp|grep mysqld tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld unix 2 [ ACC ] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock *假如不想从新启动,那可以直接手动启动。 [root@localhost mysql]#service mysqld start Starting MySQL.. SUCCESS! j. 运转客户端程序mysql,在mysql/bin名目中,测试能否连接到mysqld。 [root@localhost mysql]#/usr/local/mysql/bin/mysql Welcome to the MySQLmonitor. Commands end with ; or \g. Your MySQL connection idis 2 Server version:5.5.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement. mysql> quit Bye *此时会显现mysql>命令提醒符,可以输入sql语句,输入quit或exit退出。为了不每次都输入mysql的全途径/usr/local/mysql/bin/mysql,可将其参加环境变量中,在/etc/profile最后参加两行命令: MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin 这样就可以在shell中直接输入mysql命令来启动客户端程序了 [root@localhost mysql]#mysql Welcome to the MySQLmonitor. Commands end with ; or \g. Your MySQL connection idis 3 Server version:5.5.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other namesmay be trademarks of their respective owners. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement. mysql>
5. RPM安置步骤
a. 检查可否已安置,grep的-i选项表示匹配时忽略大小写
[root@localhost JavaEE]#rpm -qa|grep -i mysql mysql-libs-5.1.61-4.el6.x86_64 可见已经安置了库文件,应当先卸载,不然会显现覆盖错误。留意卸载时使用了--nodeps选项,忽略了依靠关系: [root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps
b. 安置MySQL的效劳器端软件,留意切换到root会员:
[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm 安置完成后,安置进程会在Linux中增加一个mysql组,乃至属于mysql组的会员mysql。可通过id命令查看: [root@localhost JavaEE]#id mysql uid=496(mysql)gid=493(mysql) groups=493(mysql) MySQL效劳器安置之后虽然配置了相关文件,但并没有主动启动mysqld效劳,需自行启动: [root@localhost JavaEE]#service mysql start Starting MySQL.. SUCCESS! 可通过检查端口可否开启来查看MySQL可否正常启动: [root@localhost JavaEE]#netstat -anp|grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld
c. 安置MySQL的客户端软件:
[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm 假如安置成功应当可以运转mysql命令,留意必需是mysqld效劳乃至开启: [root@localhost JavaEE]#mysql Welcome to the MySQLmonitor. Commands end with ; or \g. Your MySQL connection idis 1 Server version: 5.5.29MySQL Community Server (GPL) Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement. mysql>
d. RPM安置方式文件分布
Directory | Contents of Directory |
/usr/bin | Client programs and scripts |
/usr/sbin | The mysqld server |
/var/lib/mysql | Log files, databases |
/usr/share/info | Manual in Info format |
/usr/share/man | Unix manual pages |
/usr/include/mysql | Include (header) files |
/usr/lib/mysql | Libraries |
/usr/share/mysql | Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench | Benchmarks |
感激大家的阅读,但愿大家受益良多。
本文转自:https://blog.csdn.net/SuperChanon/article/details/8546254
更多教程:《linux运维》
以上就是Linux安置MySQL的两种办法的具体内容,更多请关注百分百源码网其它相关文章!