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;

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native