centos6下MySQL的簡單安裝配置

jopen 8年前發布 | 33K 次閱讀 CentOS

環境:centos6.7 32bit

數據庫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用戶沒有密碼:

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用戶的密碼為操作系統的密碼:

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


來自: http://my.oschina.net/liuyuanyuangogo/blog/604088

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!