本文目录一览:
linux怎么安装mysql5.5.11
一、准备环境
1.建立mysql安装目录及数据存放目录
[root@localhost local]# mkdir -p /usr/local/mysql //安装mysql
[root@localhost local]# mkdir -p /usr/local/mysql/data //存放数据库
2.创建myql用户和用户组
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
3.赋予数据存放目录权限
[# chown -R root:mysql . //把当前目录中所有文件的所有者设为root,所属组为mysql]
[root@localhost local]# chown mysql:mysql -R /usr/local/mysql/data
4.安装cmake[mysql5.5以后是通过cmake来编译的]
可以在网站下载cmake-2.8.4.tar.gz,上传并移动至/usr/local目录下
[root@localhost local]# tar zxvf cmake-2.8.4.tar.gz
[root@localhost local]# cd cmake-2.8.4
[root@localhost cmake-2.8.4]# ./configure --prefix=/usr/local/cmake
CMake has bootstrapped. Now run gmake.
[root@localhost cmake-2.8.4]# gmake
[root@localhost cmake-2.8.4]# gmake install
[root@localhost cmake-2.8.4]# ln -s /usr/local/cmake/bin/cmake /usr/local/bin/cmake
[root@localhost cmake-2.8.4]# cmake --version
cmake version 2.8.4
二、安装mysql
1.在mysql的网站下载mysql最新版本.地址是:
上传并移动至/usr/local/mysql目录下
2.解压mysql-5.5.20
[root@localhost local]#tar zxvf mysql-5.5.20.tar.gz
[root@localhost local]# cd mysql-5.5.20
[root@localhost mysql-5.5.20]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
[root@localhost mysql-5.5.20]# make
[root@localhost mysql-5.5.20]# make instll
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
[root@localhost mysql-5.5.20]# make clean
[root@localhost mysql-5.5.20]# rm -f CMakeCache.txt
[root@localhost mysql-5.5.20]# rm -rf /etc/my.cnf
4.把mysql的启动服务设置为系统服务
[root@localhost mysql-5.5.20]# cp support-files/my-medium.cnf /etc/my.cnf
5.初始化数据库
#cd /user/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
注:basedir:mysql安装路径 datadir:数据库文件储存路径
6.设置开机自启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
# chmod 755 /etc/init.d/mysql
# chkconfig mysql on
7.配置环境变量
将mysql的bin目录加到PATH中,有利于以后管理与维护,在/etc/profile中加入mysql/bin,同时增加两个别名方便操作:
# export PATH=/usr/local/mysql/bin:$PATH
# alias mysql_start="mysqld_safe"
# alias mysql_stop="mysqladmin -u root -p shutdown"
8.启动mysql服务
# /etc/init.d/mysql start
启动之后用ps -ef|grep mysql命令查看是否启动
9.登录mysql
# mysql -u root -p
三、安装遇到的问题
1.没有安装 gcc 和 gcc-c++,安装MYSQL执行cmake报如下错误:
[root@ice mysql-5.5.27]# cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
.
-- Configuring incomplete, errors occurred!
==================================================
解决方法:安装gcc和gcc-c++
[root@localhost mysql-5.5.20]yum install gcc
[root@localhost mysql-5.5.20]yum install gcc-c++
#删除cache文件,不删除还会报错
[root@localhost mysql-5.5.20]rm CMakeCache.txt
[root@localhost mysql-5.5.20]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
2.没有安装 ncurses-devel,安装MYSQL执行cmake报如下错误:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:257 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
解决方法:
[root@localhost mysql-5.5.20]#yum -y install ncurses-devel
[root@localhost mysql-5.5.20]#rm CMakeCache.txt
[root@localhost mysql-5.5.20]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
3.bash:mysql:command not find
原因是mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,系统在/usr/bin下面查此命令,所以找不到了。
解决方法:做个软链接即可。
# ln -s /usr/local/mysql/bin/mysql /usr/bin
4.如果myql不能远程连接,出现错误mysql error number 1130,则加入下面语句试试:
mysqlGRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;
5.[root@localhost mysql]# /etc/init.d/mysql status
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
解决方法:rm -rf /var/lock/subsys/mysql
然后启动mysql,一切正常了,这里的可能原因就是可能和log文件有关,于是将log文件给移除了,再重启MySQL终于OK了。
6.[root@localhost init.d]# /etc/init.d/mysql start
如何在linux下安装mysql
第一步:安装:
tarmysql-5.5.48-linux2.-x86_64.tar.gz
Copy到指定的路径下:
cpmysql-5.5.48-linux2.6-x86_64 /usr/local/mysql -r
添加系统mysql组合mysql用户:
执行命令:groupaddmysql和useradd -r -g mysql mysql
安装数据库:
进入安装mysql软件目录:执行命令 cd/usr/local/mysql
修改当前目录拥有者为mysql用户:执行命令chown -R mysql:mysql ./
安装数据库:执行命令./scripts/mysql_install_db --user=mysql
修改当前目录拥有者为root用户:执行命令chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令chown -R mysql:mysql data
到此数据库安装完毕
启动mysql服务和添加开机启动mysql服务:
添加开机启动:执行命令cpsupport-files/mysql.server /etc/init.d/mysql,把启动脚本放到开机初始化目录
启动mysql服务:执行命令servicemysql start
linux上怎么安装mysql
1. 运行平台:CentOS 6.3 x86_64,基本等同于RHEL 6.3
2. 安装方法:
安装MySQL主要有两种方法:一种是通过源码自行编译安装,这种适合高级用户定制MySQL的特性,这里不做说明;另一种是通过编译过的二进制文件进行安装。二进制文件安装的方法又分为两种:一种是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件;第二种是使用RPM或其他包进行安装,这种安装进程会自动完成系统的相关配置,所以比较方便。
3. 下载安装包:
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
2. 安装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
linux上如何安装mysql5.5
如果是基于Redhat的版本可以以ROOT身份在命令行界面输入:yum install mysql
如果是基于Debian的版本可以以ROOT身份在命令行界面输入:apt-get install mysql
你可以提前更新YUM库:yum update
并不定非要mysql5.5 如果你真要安装这个版本就下载rpm包 然后 rpm -ivh mysql5.5.rpm 来安装