centOS Linux下用yum安装mysql
第一篇:安装和配置MySQL
第一步:安装MySQL
[root@192 local]# yum -y install mysql-server ← 安装MySQL
[root@192 local]# yum -y install php-mysql ← 安装php-mysql
第二步:配置MySQL
[root@192 local] #vim /etc/my.cnf ← 编辑MySQL的配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1 ← 找到这一行,在这一行的下面添加新的规则,让MySQL的默认编码为UTF-8
default-character-set = utf8 ← 添加这一行
然后在配置文件的文尾填加如下语句:
[mysql]
default-character-set = utf8
第二篇:启动MySQL和初始环境设定
第一步:启动MySQL服务
[root@192 local]#chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
[root@192 local]#chkconfig --list mysqld ← 确认MySQL自启动
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
← 如果2--5为启用(或on)的状态就OK
[root@192 local]#/etc/rc.d/init.d/mysqld start ← 启动MySQL服务
初始化 MySQL
数据库: 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 192.168.0.1 password 'new-password'
Alternatively you can run:
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 test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses athttp://shop.mysql.com
[确定]
启动 mysqld: [确定]
第二步:MySQL初始环境设定
[1] 为MySQL的root用户设置密码
MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。
[root@192 local]#mysql -u root ← 在没设置密码之时,用root用户登录MySQL服务器
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011,
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> select user,host,password from mysql.user; ← 查看用户信息
mysql> select user,host,password from mysql.user;
+------+-------------+----------+
| user | host | password |
+------+-------------+----------+
| root | localhost | |
| root | 192.168.0.1 | |
| root | 127.0.0.1 | |
| | localhost | |
| | 192.168.0.1 | |
+------+-------------+----------+
5 rows in set (0.03 sec)
mysql> set password forroot@localhost=pas