您的位置:首页 > 运维架构 > Linux

Linux环境安装Mysql数据库(手工+自动两种 详细版)

2017-08-19 16:39 429 查看
参考:

http://www.linuxdiyf.com/viewarticle.php?id=65598

http://bestchenwu.iteye.com/blog/1166998

第一种安装方式:

安装MySQL后,需要初始化 授权表、启动服务器,并确保服务器工作正常。你还要让服务器随系统的启动和停止自动启动和停止。应当为授权表中的账户指定密码。在某些安装中,该程序自动运行。

1、添加mysql用户组以及用户

groupadd mysql

useradd -g mysql mysql

2、解压mysql 并制定安装目录

cd /root/software/

tar xvzf mysql-5.1.68.tar.gz

cd mysql-5.1.68

3、configure

第一次配置 configure

./configure –prefix=/usr/local/mysql/ –with-server-suffix=-unionread-edition –enable-assembler –enable-local-infile –enable-thread-safe-client –with-charset=utf8 –with-extra-charsets=gbk,gb2312,utf8,ascii –with-readline –with-ssl –with-embedded-server –with-pthread –with-mysqld-user=mysql –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-plugins=partition,innobase,innodb_plugin

报错:

checking for tgetent in -lncursesw… no

checking for tgetent in -lncurses… no

checking for tgetent in -lcurses… no

checking for tgetent in -ltermcap… no

checking for tgetent in -ltinfo… no

checking for termcap functions library… configure: error: No curses/termcap library found

**问题:**configure时遇到缺少ncurses依赖包

解决:

查看nucrses并安装ncurses依赖包

yum list|grep ncurses

yum -y install ncurses-devel

安装完成以后重新配置 configure

./configure –prefix=/usr/local/mysql/ –with-server-suffix=-unionread-edition –enable-assembler –enable-local-infile –enable-thread-safe-client –with-charset=utf8 –with-extra-charsets=gbk,gb2312,utf8,ascii –with-readline –with-ssl –with-embedded-server –with-pthread –with-mysqld-user=mysql –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-plugins=partition,innobase,innodb_plugin

Thank you for choosing MySQL! mysql安装的第一步成功

4、make && make install

报错:

make[1]: Entering directory
/root/software/mysql-5.1.68/mysys'

source='my_new.cc' object='my_new.o' libtool=no \

DEPDIR=.deps depmode=none /bin/sh ../depcomp \

g++ -DDEFAULT_BASEDIR=\"/home/mysql\" -DMYSQL_DATADIR="\"/home/mysql/var\"" -DDEFAULT_CHARSET_HOME="\"/home/mysql\"" -DSHAREDIR="\"/home/mysql/share/mysql\"" -DDEFAULT_HOME_ENV=MYSQL_HOME -DDEFAULT_GROUP_SUFFIX_ENV=MYSQL_GROUP_SUFFIX -DDEFAULT_SYSCONFDIR="\"/home/mysql/etc\"" -DHAVE_CONFIG_H -I. -I../include -I../include -I../include -I.    -O    -fno-implicit-templates -fno-exceptions -fno-rtti -c -o my_new.o my_new.cc

../depcomp: line 571: exec: g++: not found

make[1]: *** [my_new.o] Error 127

make[1]: Leaving directory
/ro
4000
ot/software/mysql-5.1.68/mysys’

make: * [all-recursive] Error 1

问题:g++ not found 。

对比查看发现GCC已经安装但缺少g++,所以make时报错。

安装gcc-c++

[root@open2 ~/software]# yum -y install gcc-c++

第三次 ./configure

./configure –prefix=/usr/local/mysql/ –with-server-suffix=-unionread-edition –enable-assembler –enable-local-infile –enable-thread-safe-client –with-charset=utf8 –with-extra-charsets=gbk,gb2312,utf8,ascii –with-readline –with-ssl –with-embedded-server –with-pthread –with-mysqld-user=mysql –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-plugins=partition,innobase,innodb_plugin

make && make install

漫长的等待。

5、初始化授权表:

/usr/local/mysql/bin/mysql_install_db –user=mysql –datadir=/var/lib/mysql/

copy配置文件:

cp /usr/local/mysql/share/my-medium.cnf /etc/my.cnf

6、启动mysql服务

/usr/local/mysql/bin/mysqld_safe &

设置启动服务

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld

chkconfig –add mysqld

chkconfig –level 345 mysqld on

复制mysql启动到用户path下

cp /usr/local/mysql/bin/mysql /usr/bin/mysql

启动mysql

service mysqld start

键入mysql 或者 全路径 /usr/local/mysql/bin/mysql

可以登陆了。

7、修改root密码

/usr/local/mysql/bin/mysqladmin -uroot password XXXXXX

再次登陆

mysql -uroot -p

第二种方式 rpm安装包手动安装

1)软件包:

MySQL-server-community-5.1.54-1.rhel5.x86_64.rpm

MySQL-client-community-5.1.54-1.rhel5.x86_64.rpm

2)安装命令:

rpm -ivh MySQL-server-community-5.1.54-1.rhel5.x86_64.rpm

rpm -ivh MySQL-client-community-5.1.54-1.rhel5.x86_64.rpm

执行安装时报错:

[root@open2 ~/software]# rpm -ivh MySQL-server-community-5.1.54-1.rhel5.x86_64.rpm

Preparing… ########################################### [100%]

file /usr/share/mysql/spanish/errmsg.sys from install of MySQL-server-community-5.1.54-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64

file /usr/share/mysql/swedish/errmsg.sys from install of MySQL-server-community-5.1.54-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64

file /usr/share/mysql/ukrainian/errmsg.sys from install of MySQL-server-community-5.1.54-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64

错误提示server与mysql-libs-5.1.66包冲突。

解决思路,先移除冲突的libs包,在进行安装

[root@open2 ~/software]# rpm -qa |grep mysql

mysql-libs-5.1.66-2.el6_3.x86_64

[root@open2 ~/software]# yum -y remove mysql-libs-5.1.66*

[root@open2 ~/software]# rpm -ivh MySQL-server-community-5.1.54-1.rhel5.x86_64.rpm

成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: