MySQL在centos6下的yum安裝使用

環境:centos6.7 32bitphp

數據庫MySQL的安裝配置mysql

1.安裝

[root@cloudstack Desktop]# yum -y install mysql-server
Loaded plugins: fastestmirror, refresh-packagekit, security
 .......
Dependency Installed:
  mysql.i686 0:5.1.73-5.el6_6         perl-DBD-MySQL.i686 0:4.013-3.el6        
  perl-DBI.i686 0:1.609-4.el6        
Complete!


[root@cloudstack Desktop]# yum -y install php-mysql
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
......
Installed:
  php-mysql.i686 0:5.3.3-46.el6_6                                               
Dependency Installed:
  php-common.i686 0:5.3.3-46.el6_6         php-pdo.i686 0:5.3.3-46.el6_6        
Complete!

2.啓動

[root@cloudstack Desktop]# /etc/rc.d/init.d/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 cloudstack.lyy.com 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  ]

3.經過root用戶(此時並無密碼)登錄

[root@cloudstack Desktop]# mysql -u root
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>

  查看當前root用戶沒有密碼:sql

mysql> select user, host, password from mysql.user;
+------+--------------------+----------+
| user | host               | password |
+------+--------------------+----------+
| root | localhost          |          |
| root | cloudstack.lyy.com |          |
| root | 127.0.0.1          |          |
|      | localhost          |          |
|      | cloudstack.lyy.com |          |
+------+--------------------+----------+
5 rows in set (0.00 sec)

 設置root用戶的密碼爲操做系統的密碼:shell

mysql> set password for root@localhost=password('centos6');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@cloudstack.lyy.com=password('centos6');
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host, password from mysql.user;
+------+--------------------+-------------------------------------------+
| user | host               | password                                  |
+------+--------------------+-------------------------------------------+
| root | localhost          | *D53AD928B433F60B05A0B29CA1BCEA6809AC1B9D |
| root | cloudstack.lyy.com | *D53AD928B433F60B05A0B29CA1BCEA6809AC1B9D |
| root | 127.0.0.1          |                                           |
|      | localhost          |                                           |
|      | cloudstack.lyy.com |                                           |
+------+--------------------+-------------------------------------------+
5 rows in set (0.00 sec)
mysql> exit
Bye

 退出mysql,並從新使用root用戶登陸,驗證修改後的密碼。數據庫

[root@cloudstack Desktop]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@cloudstack Desktop]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
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> exit
Bye
相關文章
相關標籤/搜索