>  기사  >  운영 및 유지보수  >  Linux에 MySQL을 설치하는 두 가지 방법

Linux에 MySQL을 설치하는 두 가지 방법

卡哇伊
卡哇伊원래의
2020-07-15 17:32:4415212검색

Linux에 MySQL을 설치하는 두 가지 방법1. 실행 플랫폼: CentOS 6.3 x86_64, 기본적으로 RHEL 6.3

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.

4. 일반 설치 단계

a.                                                                                                                   .

MySQL-server-5.5.29-2.el6.x86_64.rpm
MySQL-client-5.5.29-2.el6.x86_64.rpm

c. 여기서는 /usr/local

[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

d로 지정하는 지정된 설치 디렉터리에 바이너리 파일을 추출합니다. /usr/local/mysql/

Directory디렉토리 내용binmysqlddatadocs manincludelibscriptsmysql_install_dbsharesql-bench

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安装方式文件分布

클라이언트 프로그램 및
서버

로그 파일, 데이터베이스

정보 형식의 설명서

Unix 매뉴얼 페이지

Include(헤더) 파일

라이브러리

기타 지원 파일(오류 메시지, 샘플 구성 파일, 데이터베이스 설치용 SQL 포함)

벤치마크

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을 설치하는 두 가지 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.