您的位置:首页 > 运维架构 > Linux

centos 下yum 快速安装配置mysql

2017-01-04 00:00 344 查看

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, 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.

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: