欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

CentOS 安装MySQL

程序员文章站 2022-06-10 12:20:43
...

鉴于菜鸟,解释下【安装mysql】,因为要在linux上使用mysql数据库,但又不清楚mysql的运行方式,故用个笼统的名词。其实,mysql分

鉴于菜鸟,解释下【安装mysql】,因为要在linux上使用mysql数据库,但又不清楚mysql的运行方式,故用个笼统的名词。

其实,mysql分为mysql server与mysql client,故,这两个【软件包】都必须安装上。

曾经犯的错误:

尤其之前不清楚mysql server 与 mysql client,打开终端后,输入:mysql,返回无此命令。

然后想当然地使用:

yum install mysql

最后这条能执行,还能安装(安装什么不知道),安装完成后,用命令:

whereis mysql

还能找到相应的文件和二进制文件。但执行:

mysql

出现的是无法打开 ***** sokcet。(猜测,,server没启)。

server mysql status

chkconfig --list mysql

都没有相应的mysql出现,当然也没有3306端口被使用(mysqld的默认端口)。

弄了大半天,有些肯定mysql server没安装。

总结:

之所以犯这样的错误,主要是没弄清楚我要mysql工作,需要安装些什么软件,以及没弄明白一些命令的真正功能(如,yum install msyql)。当然,现在也有许多是一知半解的,如有错误,欢迎拍砖。

正确的做法:

1、在官网分别下载mysql server, mysql client。

这里要注意的地方:

【1】下载时要选择自己电脑的类型,我选的是:Linux Generic(因为我用图形界面安装时,默认选的就是这个)。

【2】要看清楚下载的软件包,因为那里面有component, lib等,所以得看清楚(当时我就下了个component),还得分清楚是32位的,还是64位的。

我下载的是:

MySQL-server-5.5.27-1.linux2.6.i386.rpm

MySQL-client-5.5.27-1.linux2.6.i386.rpm

(在终端直接用wget)。

2、安装mysql server。

在下载的目录:

rpm -ivh MySQL-server-5.5.27-1.linux2.6.i386.rpm

正常情况会默认安装好(比较快)。

一般安装好后,会要修改登录的密码等(我没有设置):

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

3、安装mysql client

rpm -ivh MySQL-client-5.5.27-1.linux2.6.i386.rpm

4、启动mysql server

service mysql start

这时,查看端口时,就会发现3306这个端口被mysqld占用着。

[xxh@pc-20101003hbjg ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql安装成功,这是就可以用mysql了。

CentOS 安装MySQL