在linux系统中安装mysql服务器详细步骤并解决ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passw
1、首先下载MySQL的安装文件,我这里安装的是MySQL5.1.7版本的
2、查看linux系统中是否安装了mysql 执行:rpm -qa|grep -i mysql 如有会显示已安装的Mysql版本,我的显示mysql-libs-5.1.61-4.el6.i686
3、这时如果有的话就强制删除:rpm -e --nodeps mysql-libs-5.1.61-4.el6.i686(因为有包依赖,所以要强制删除)
在你没有强制删除时安装mysql
我的报错提示如下:
MySQL-server-5.1.7-0.i386.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/READMEfrom install of MySQL-server-5.1.7-0.i386.rpm conflicts with file frompackagemysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/Index.xmlfrom install of MySQL-server-5.1.7-0.i386.rpm conflicts with file frompackagemysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/armscii8.xmlfrom install of MySQL-server-5.1.7-0.i386.rpm conflicts with file frompackagemysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/ascii.xmlfrom install of MySQL-server-5.1.7-0.i386.rpm conflicts with file frompackagemysql-libs-5.1.61-4.el6.i686
file /usr/share/mysql/charsets/cp1250.xmlfrom install of MySQL-server-5.1.7-0.i386.rpm conflicts with file frompackagemysql-libs-5.1.61-4.el6.i686 。。。。。。
4、到mysql安装包路径下执行:rpm -ivh MySQL-server-5.1.7-0.i386.rpm 我这里安装成功了,但是mysql服务无法启动,总是启动失败,后来百度了一下,是因为selinux的原因,只要将selinux关闭就OK了。关闭selinux:vi /etc/selinux/config 将SELINUX=enforcing改成SELINUX=disabled然后重启
5、关闭selinux之后还是无法启动mysql服务,因为安装的mysql所有者是root,在安装mysql的时候会创建一个用户mysql,只要将/var/lib/mysql的所有者改为mysql就OK了,执行命令:chown -R mysql:mysql /var/lib/mysql
6、现在执行:service mysql start
7、安装MySQL客户端
执行命令rpm -ivhMySQL-client-5.1.7-0.i386.rpm进行安装。
8、安装成功
成功安装MySQL后将sql文件导入到数据库,步骤如下:
进入MYSQL Command Line Client
1、先创建数据库:create database test注:test是创建数据库的名称
2、再切换到当前数据库:use test
3、再输入:\. /root/test.sql或 souce /root/test.sql
按照以上步骤就可以将备份的sql脚本导入到linux中的数据库中去。
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
使用网上介绍的方法修改root用户的密码:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
现在终于被我找到了解决方法,如下(请先测试方法三,谢谢!):
方法一:
# /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/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
mysql>
更多推荐
所有评论(0)