当前位置: 移动技术网 > IT编程>数据库>Mysql > linux下讲解MySQL安装与登录方法

linux下讲解MySQL安装与登录方法

2017年12月12日  | 移动技术网IT编程  | 我要评论
fedora5下配置mysql (很有参考价值的 mysql资料 包括如何在linux文件系统移动mysql数据库的位置)

一、下载mysql安装文件

完全安装mysql需要下面6个文件:

mysql-server-community-5.1.26-0.rhel4.i386.rpm

mysql-client-community-5.1.26-0.rhel4.i386.rpm

mysql-shared-community-5.1.26-0.rhel4.i386.rpm

mysql-devel-community-5.1.26-0.rhel4.i386.rpm

mysql-test-community-5.1.26-0.rhel4.i386.rpm

mysql-community-debuginfo-5.1.26-0.rhel4.i386.rpm

下载地址为:http://dev.mysql.com/downloads/mysql/5.1.html#linux-rhel4- x86-32bit-rpms,打开此网页(因为没有找到fedora版本的,就用redhat enterprise 4来代替了,没有问题),下载所有的需要的上述rpm文件。

二、mysql安装

rpm文件是red hat公司开发的软件安装包,rpm可让linux在安装软件包时免除许多复杂的手续。该命令在安装时常用的参数是 –ivh ,其中i表示将安装指定的rmp软件包,v表示安装时的详细信息,h表示在安装期间出现“#”符号来显示目前的安装过程。这个符号将持续到安装完成后才停止。

1) mysql安装服务器端

在有两个rmp文件的目录下运行如下命令: [root@test1 local]# rpm -ivh mysql-server*.rpm(*为通配符,省掉了很多的输入,很方便-:)))

显示如下信息:failed dependencies:perl(dbi) is needed by mysql-server-5.1.26-0.rhel4.i386出错了!

去 google下,发现可能是该版本的rpm里增加了很多附加依赖的检查,特别是对所有perl modules的依赖检查,因此用“--nodeps”来强制安装是安全的,我正是这么做的:rpm -ivh mysql-server*.rpm --nodeps;结果成功:

preparing... [100%]

1:mysql-server [100%]

2) mysql安装客户端

运行如下命令:

[root@test1 local]# rpm -ivh mysql-client*.rpm

preparing... [100%]

1:mysql-client [100%]

如上安装其他的4个rpm文件,应该没有什么问题。

三、mysql登录

mysql登录的命令是mysql, mysql 的使用语法如下: mysql [-u username] [-h host] [-p[password]] [dbname] username 与 password 分别是 mysql用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个root用户不是linux的系统用户。mysql默认用户是 root,由于初始没有密码,第一次进时只需键入mysql即可。

[root@test1 local]# mysql

welcome to the mysql monitor. commands end with ; or g.

your mysql connection id is 1 to server version: 4.0.16-standard

type 'help;' or 'h' for help. type 'c' to clear the buffer.

mysql>

出现了“mysql>”提示符,恭喜你,安装成功!

增加了密码后的登录格式如下:

mysql -u root -p

enter password: (输入密码)

其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。

可是我输入mysql却出错了:

初始密码是空的,我输入的也是空的还是错误!

error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)

mysql安装解决方法:重改密码

# /etc/init.d/mysql stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> update user set password=password('newpassword') where user='root';

mysql> flush privileges;

mysql> quit

# /etc/init.d/mysqld restart

# mysql -uroot -p

enter password:

mysql>搞定!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网