mysql基本配置
系统环境:RHEL6.0 x86-64
server1:192.168.0.1
server2:192.168.0.2
####在server1上做如下操作
yum install mysql mysql-server -y
/etc/init.d/mysqld start #开启mysql服务
####基本操作
mysql > create database westos;
mysql > show databases;
mysql > use westos;
mysql > create table users (username varchar(25) not null, password varchar(25) not null);
mysql > desc users #显示表的结构
+----------+--------------+-----+------+------+-------+
|Field |Type
|Null |Key Default|Extra|
+----------+--------------+-----+------+------+-------+
|username| varchar(25)| NO | NULL|
|password | varchar(25)| NO | NULL|
+----------+--------------+-----+------+------+-------+
2 rows in set(0.00 sec)
####insert into tables_name values(date)
mysql > insert into users values ("Jack","123");
mysql > select * from users;
+-------------+-------------+
|username |password |
+-------------+-------------+
|Jack |123 |
+-------------+-------------+
1 row in set (0.00 sec)
####update tables_name set .... where ....;
mysql > update users set password=password(123) where username="Jack";
mysql > select * from users;
+--------------+------------------------------------------+
|username |password
+--------------+------------------------------------------+
|Jack |*531E182E2F772080AB0740FE2
+--------------+------------------------------------------+
mysql > update users set password="456";
mysql > select * from users;
+-----------------+---------------+
|username | password
+-----------------+---------------+
|Jack | 456
+-----------------+---------------+
1 row in set(0.00sec)
####delete from tables_name where....;
mysql > delete from users where username="Jack";
mysql > delete from users;
mysql > select * from users;
Empty set(0.00 sec)
mysql > desc users;
+----------+--------------+-----+------+------+-------+
|Field |Type
|Null |Key Default|Extra|
+----------+--------------+-----+------+------+-------+
|username| varchar(25)| NO | NULL|
|password | varchar(25)| NO | NULL|
+----------+--------------+-----+------+------+-------+
2 rows in set (0.00sec)
mysql > show tables;
mysql > select * from users;
mysql > drop table users; #删除表
mysql > drop database westos; #删除库
####为mysql添加登录用户
grant select, insert, update, delete on *.* to user1@"%" identified by "123";
grant select, insert, update, delete on aaa.* to user2@localhost identified by "456";
连接mysql-server在客户端mysql -uuser -ppassword -h mysql-server
mysql > grant all on westos.* to user1@localhost identified by '123';
mysql > grant select on *.* to user2@192.168.0.2 identified by '456';
mysql > flush privileges; #重载授权
####在server2等mysql-server测试
yum install mysql -y #安装mysql客户端
mysql -uuser2 -p -h 192.168.0.2
Enter password:456
####数据备份
cd /var/lib/mysql
mysqldump -uroot -predhat mysql > mysql.bak
less mysql.bak
####数据恢复
mysql -uroot -predhat westos < mysql.bak #数据库westos必须已存在
####忘记管理员密码
/etc/init.d/mysqld stop
mysqld_safe--skip-grant-tables #跳过mysql的访问控制
/etc/init.d/mysqld start
mysql > update user set password=redhat where user='root';
mysqladmin -uroot -predhat password westos
mysqladmin -uusername -p old_password new_password
describe tables_name; #显示表的数据结构
####通过WEB界面管理mysql
cd /var/www/html
tar -zxf phpMyAdmin-2.11.3-all-languages.tar.bz2
mv phpMyAdmin-2.11.3-all-languages phpMyAdmin
cd phpMyAdmin
cp config.sample.inc.php config.inc.php
vim config.inc.php
....
$cfg['blowfush_secret'] = 'breezy';
yum install php php-mysql -y #安装php及php和mysql接口软件
URL= #通过WEB界面操作mysql数据库
GOOD LUCK!!!!
阅读(1413) | 评论(0) | 转发(0) |