微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos 下yum 快速安装配置mysql

1.1在centos执行命令:

yum install -y MysqL-server MysqL MysqL-deve

直到: Complete!。

1.2第一次启动MysqL:(提示如何设置密码)

[root@hadoop1 hadoop]# service MysqLd start
Initializing MysqL database: Installing MysqL system tables...
OK
Filling help tables...
OK

To start MysqLd at boot time you have to copy
support-files/MysqL.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MysqL root USER !
To do so,start the server,then issue the following commands:

/usr/bin/MysqLadmin -u root password 'new-password'
/usr/bin/MysqLadmin -u root -h hadoop1 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.

You can start the MysqL daemon with:
cd /usr ; /usr/bin/MysqLd_safe &

You can test the MysqL daemon with MysqL-test-run.pl
cd /usr/MysqL-test ; perl MysqL-test-run.pl

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

[ OK ]
Starting MysqLd: [ OK ]

1.3根据提示设置初始化密码:

[root@hadoop1 hadoop]# /usr/bin/MysqLadmin -u root password 'root'

提示错误如下
/usr/bin/MysqLadmin: connect to server at 'localhost' Failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

2.1解决不能正常登陆

2.1.1停止服务

[root@hadoop1 hadoop]# service MysqLd stop
Stopping MysqLd: [ OK ]

2.1.2安全模式启动

[root@hadoop1 hadoop]# MysqLd_safe --skip-grant-tables &
[1] 7371
[root@hadoop1 hadoop]# 170105 07:44:29 MysqLd_safe Logging to '/var/log/MysqLd.log'.
170105 07:44:29 MysqLd_safe Starting MysqLd daemon with databases from /var/lib/MysqL

2.1.3无需账号密码登陆

MysqL -uroot -p
Enter password: #注释:直接回车就好
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 1
Server version: 5.1.73 Source distribution

copyright (c) 2000,2013,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.

2.1.4手动修改密码

MysqL> use MysqL
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MysqL> update user set password=password("root") where user='root' and host='localhost';
Query OK,1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MysqL> flush privileges
-> ;
Query OK,0 rows affected (0.00 sec)

MysqL> quit
Bye

2.1.5正常启动

[root@hadoop1 hadoop]# service MysqLd restart
170105 07:47:15 MysqLd_safe MysqLd from pid file /var/run/MysqLd/MysqLd.pid ended
Stopping MysqLd: [ OK ]
Starting MysqLd: [ OK ]

[root@hadoop1 hadoop]# MysqL -uroot -proot
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 2
Server version: 5.1.73 Source distribution

copyright (c) 2000,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>

3解决客户端远程无法连接的问题

错误信息:Host '192.168.156.1' is not allowed to connect to this MysqL server

解决办法:

3.1修改

MysqL> use MysqL;

MysqL> update user set host = '%' where user = 'root';

MysqL> select * from user where user='root' \G;

查看是否修改成功

3.2授权法

MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.156.1' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK,0 rows affected (0.01 sec)

MysqL> flush privileges;

原文地址:https://www.jb51.cc/centos/379212.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。