在linux环境下安装MySQL

1 篇文章 0 订阅

2.2. Installing MySQL fromGeneric Binaries on Unix/Linux

Oracleprovides a set of binary distributions of MySQL. These include binarydistributions in the form of compressedtar files (files with a .tar.gzextension) for a number of platforms, as well as binaries in platform-specificpackage formats for selected platforms.

This section covers the installation of MySQL from acompressed tar file binary distribution. For other platform-specificpackage formats, see the other platform-specific sections. For example, forWindows distributions, seeSection 2.3, “Installing MySQLon Microsoft Windows”.

To obtain MySQL, see Section 2.1.3, “How to Get MySQL”.

首先得下载安装包,建议去:http://dev.mysql.com/downloads/mirrors.html,选择一个镜像下载就行了。千万注意了,如果不是64位的机器,后缀千万不能是“-x86_64.tar.gz”,否则必然出错,笔者就走了大弯路,还莫名其妙很久。例如一个正确的下载的是:mysql-5.5.15-linux2.6-i686.tar.gz

MySQL compressed tar file binary distributionshave names of the form mysql-VERSION-OS.tar.gz, whereVERSIONis a number (for example, 5.5.18), andOS indicates the type ofoperating system for which the distribution is intended (for example,pc-linux-i686 or winx64).

To install MySQL from a compressed tar filebinary distribution, your system must have GNU gunzip to uncompress thedistribution and a reasonabletar to unpack it. If yourtarprogram supports the z option, it can both uncompress and unpack the file.

GNU tar is known to work. The standard tarprovided with some operating systems is not able to unpack the long file namesin the MySQL distribution. You should download and install GNUtar, orif available, use a preinstalled version of GNU tar. Usually this is availableasgnutar,gtar, or astar within a GNU or Free Softwaredirectory, such as /usr/sfw/bin or /usr/local/bin. GNUtar is availablefromhttp://www.gnu.org/software/tar/.

Warning

If you have previously installed MySQL using youroperating system native package management system, such as yum or apt-get, youmay experience problems installing using a native binary. Make sure yourprevious MySQL previous installation has been removed entirely (using yourpackage management system), and that any additional files, such as old versionsof your data files, have also been removed. You should also check the existenceof configuration files such as /etc/my.cnf or the /etc/mysql directory have been deleted.

If you run into problems and need to file a bugreport, please use the instructions inSection 1.7, “How to ReportBugs or Problems”.

On Unix, to install a compressed tar filebinary distribution, unpack it at the installation location you choose(typically /usr/local/mysql). This creates the directories shown in thefollowing table.

Table 2.2. MySQL Installation Layout for Generic Unix/LinuxBinary Package 介绍一下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

Debug versions of the mysqld binary are available as mysqld-debug. To compile your own debug versionof MySQL from a source distribution, use the appropriate configuration optionsto enable debugging support. For more information on compiling from source, see Section 2.9, “Installing MySQL from Source”.


To install and use a MySQL binarydistribution, the basic command sequence looks like this:(以下就是安装步骤)

shell>groupadd mysql

shell>useradd -r -g mysql mysql

shell>cd /usr/local

shell>tar zxvf /path/to/mysql-VERSION-OS.tar.gz

shell>ln -s full-path-to-mysql-VERSION-OS mysql

shell>cd mysql

shell>chown -R mysql .

shell>chgrp -R mysql .

shell>scripts/mysql_install_db --user=mysql注释

shell>chown -R root .

shell>chown -R mysql data

# Next command is optional

shell>cp support-files/my-medium.cnf /etc/my.cnf

shell>bin/mysqld_safe --user=mysql &

# Next command is optional

shell>cp support-files/mysql.server /etc/init.d/mysql.server


注释

Ubuntu下安装MySQL出现FATALERROR: Could not find mysqld的处理

错误信息:

#./bin/mysql_install_db–user=mysql

 

FATALERROR: Could not find mysqld

 

Thefollowing directories were searched:

 

/usr/libexec

/usr/sbin

/usr/bin

 

If youcompiled from source, you need to run ‘make install’to copy the software intothe correct location ready for operation.

 

If youare using a binary release, you must either be at the top of the level of theextracted archivem or pass the –basedir option pointing to that location.

 

解决办法:

scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql

 

A more detailed version of the preceding descriptionfor installing a binary distribution follows.

Note

This procedure assumes that you haveroot (administrator) access to your system. Alternatively, you can prefix eachcommand using thesudo (Linux) orpfexec (OpenSolaris) command.

The procedure does not set up anypasswords for MySQL accounts. After following the procedure, proceed toSection 2.10, “PostinstallationSetup and Testing”.

Create a mysql User and Group

If your system does not already have a user and groupfor mysqld to run as, you may need to createone. The following commands add the mysql group and the mysql user. You mightwant to call the user and group something else instead of mysql. If so,substitute the appropriate name in the following instructions. The syntax for useraddand groupadd may differ slightly on different versions of Unix, or theymay have different names such asadduser andaddgroup.

shell>groupadd mysql

shell>useradd -r -g mysql mysql

Note

Because the user is required onlyfor ownership purposes, not login purposes, theuseradd command uses the-r option to createa user that does not have login permissions to your server host. Omit thisoption to permit logins for the user (or if youruseradd does notsupport the option).

Obtain and Unpack the Distribution

Pick the directory under which you want to unpack thedistribution and change location into it. The example here unpacks thedistribution under /usr/local.The instructions, therefore, assume that you have permission to create filesand directories in /usr/local. If that directory is protected, you must performthe installation as root.

shell>cd /usr/local

Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”. For a given release, binarydistributions for all platforms are built from the same MySQL sourcedistribution.

Unpack the distribution, which creates theinstallation directory. Then create a symbolic link to that directory.tarcan uncompress and unpack the distribution if it has z option support:

shell>tar zxvf /path/to/mysql-VERSION-OS.tar.gz

shell>ln -s full-path-to-mysql-VERSION-OS mysql

The tar command creates a directory namedmysql-VERSION-OS. The ln command makes a symbolic link to thatdirectory. This enables you to refer more easily to the installation directoryas /usr/local/mysql.

If your tar does not have z option support,use gunzip to unpack the distribution and tar to unpack it.Replace the precedingtar command with the following alternative commandto uncompress and extract the distribution:

shell>gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -

Perform Postinstallation Setup

The remainder of the installation process involvessetting up the configuration file, creating the core databases, and startingthe MySQL server. For instructions, seeSection 2.10, “PostinstallationSetup and Testing”.

Note

The accounts that are listed in theMySQL grant tables initially have no passwords. After starting the server, youshould set up passwords for them using the instructions inSection 2.10, “PostinstallationSetup and Testing”.


Copyright © 1997, 2011, Oracle and/or its affiliates. Allrights reserved.Legal Notices

 


中文安装指南:

Linux平台下如何使用MySQL免安装版(二进制版)

【1】MySQL免安装版/二进制版软件,不用编译,
下载地址:http://dev.mysql.com/downloads/mirrors.html

文件格式:MYSQL-VERSION-OS.tar.gz

【2】创建mysql组,建立mysql用户并加入到mysql组中。

不同版本的Unix中,groupadd和useradd的语法可能会稍有不同。

#groupadd mysql
#useradd -g mysql mysql


【3】进入目录/usr/local,解压缩免安装版,并在此目录中建立名为mysql的软链接。

#cd /usr/local/src 设定你的安装包已经放在了该目录底下的
#tar zxvf mysql-VERSION-OS.tar.gz
#ln -s /usr/local/src/MYSQL-VERSION-OS mysql  


【4】添加MySQL配置文件。

如果你想要设置一个选项文件,使用support-files目录中的一个作为模板。
在这个目录中有4个模板文件,是根据不同机器的内存定制的。

#cp support-files/my-medium.cnf /etc/my.cnf

可能你需要用root用户运行这些命令。

【5】设定目录访问权限,用 mysql_install_db 创建MySQL授权表初始化,并设置mysql,root帐号访问权限。

#cd mysql
#chown -R mysql .
#chgrp -R mysql .
#scripts/mysql_install_db --user=mysql 【可能出错】
#chown -R root .
#chown -R mysql data


注意以上命令中的" . "符号不能少。
【可能出错1】
error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
【解决办法】
libaio是Linux项目的一个库。它将用户提交的写操作用异步的方式执行。通过 回调用户的代码来通知写操作的完成。
到http://download.csdn.net/download/danhua/1464413下载“libaio-0.3.104.tar.gz”:解压后编译make 安装make install
【可能出错2】
FATAL ERROR:Could not find mysqld
【解决办法】
#scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &

【6】运行mysql

#bin/mysqld_safe --user=mysql  【可能出错】

启动mysql:bin/mysqld_safe --user=mysql &
安装或者二进制安装的可以直接使用如下命令启动和停止mysql: /etc/init.d/mysql start|stop|restart

如果没有问题的话,应该会出现类似这样的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var

如果出现 mysql ended这样的语句,表示Mysql没有正常启动,你可以到log中查找问题,
Log文件的通常在/etc/my.cnf中配置。大多数问题是权限设置不正确引起的。
【可能出错1】
Can't find messagefile '/usr/share/errmsg.sys'
【解决办法1】
sudo mysqld_safe --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql &

(添加language=...报错不理会:An old style --language value with language specific part detected:/usr/local/mysql/share/english)

【可能出错2】
Can’t start server : Bind on unix socket: Permission denied解决方法:
【解决办法2】改变你mysql编译安装目录的权限: chown -R mysql:mysql /usr/local/mysql

【7】设置root密码。默认安装密码为空,为了安全你需要修改密码。

#/usr/local/mysql/bin/mysqladmin -u root password '123456'

【8】拷贝编译目录的一个脚本,设置开机自动启动。

#cp support-files/mysql.server /etc/init.d/mysqld
#chmod 700 /etc/init.d/mysqld
#chkconfig --add mysqld  【可能出错】
#chkconfig --level 345 mysqld on

【可能出错】
chkconfig 没有安装
【解决办法】
http://download.csdn.net/detail/wangjiannuaa/3707269下载安装
补充:
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。
使用语法:
chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]

【9】软连接命令
把MYSQLPATH/bin/mysql映射到/usr/local/bin目录下:
#cd /usr/local/bin
#ln -fs /usr/local/mysql/bin/mysql mysql

还有其它常用命令mysqladmin, mysqldump等 例如
#ln -fs /usr/local/mysql/bin/mysql mysql
#ln -fs /usr/local/mysql/bin/mysqld_safe mysqld_safe


【10】启动mysqld服务。

#service mysqld start

【11】查看3306端口是否打开。要注意在防火墙中开放该端口。

#netstat -atln  


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值