[root@test1 local]# rpm -ivh MySQL-server-4.0.16-0.i386.rpm 显示如下信息。 warning: MySQL-server-4.0.16-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] 。。。。。。(省略显示) /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h test1 password 'new-password' 。。。。。。(省略显示) Starting mysqld daemon with databases from /var/lib/mysql
[root@test1 local]# netstat -nat Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@test1 local]# rpm -ivh MySQL-client-4.0.16-0.i386.rpm warning: MySQL-client-4.0.16-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 Preparing... ########################################### [100%] 1:MySQL-client ########################################### [100%]
mysql [-u username] [-h host] [-p[password]] [dbname]
[root@test1 local]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.0.16-standard Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
usr/bin/mysqladmin -u root password 'new-password'
格式:mysqladmin -u用户名 -p旧密码 password 新密码
例1:给root加个密码123456。
键入以下命令 :
[root@test1 local]# /usr/bin/mysqladmin -u root password 123456
3、测试是否修改成功
1)不用密码登录[root@test1 local]# mysql ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO) 显示错误,说明密码已经修改。
[root@test1 local]# mysql -u root -p Enter password: (输入修改后的密码123456) Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 4.0.16-standard Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
1、启动
[root@test1 init.d]# /etc/init.d/mysql start
2、停止
/usr/bin/mysqladmin -u root -p shutdown
[root@test1 local]# /sbin/chkconfig –list
[root@test1 local]# /sbin/chkconfig – add mysql
[root@test1 local]# /sbin/chkconfig – del mysql
六、更改MySQL目录
1、home目录下建立data目录
cd /home mkdir data
mysqladmin -u root -p shutdown
mv /var/lib/mysql /home/data/
4、找到my.cnf配置文件
如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf)中。命令如下:[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
vi my.cnf (用vi工具编辑my.cnf文件,找到下列数据修改之) # The MySQL server [mysqld] port = 3306 #socket = /var/lib/mysql/mysql.sock(原内容,为了更稳妥用“#”注释此行) socket = /home/data/mysql/mysql.sock (加上此行)
[root@test1 etc]# vi /etc/rc.d/init.d/mysql #datadir=/var/lib/mysql (注释此行) datadir=/home/data/mysql (加上此行)
/etc/rc.d/init.d/mysql start
mysql> show databases; +----------+ | Database | +----------+ | mysql | | test | +----------+
mysql> use mysql; (打开库,对每个库进行操作就要打开此库,类似于foxpro ) Database changed mysql> show tables; +-----------------+ | Tables_in_mysql | +-----------------+ | columns_priv | | db | | func | | host | | tables_priv | | user | +-----------------+ 6 rows in set (0.01 sec)
describe 表名;
select * from 表名;
Select * from user;
create database 库名;
mysql> create databases aaa;
use aaa; mysql> create table name (id int(3) auto_increment not null primary key, xm char(8),xb char(2),csny date);
mysql> describe name; +-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | id | int(3) | | PRI | NULL | auto_increment | | xm | char(8) | YES | | NULL | | | xb | char(2) | YES | | NULL | | | csny | date | YES | | NULL | | +-------+---------+------+-----+---------+----------------+
例如:增加几条相关纪录。
mysql> insert into name values('','张三','男','1971-10-01'); mysql> insert into name values('','白云','女','1972-05-20');
mysql> select * from name; +----+------+------+------------+ | id | xm | xb | csny | +----+------+------+------------+ | 1 | 张三 | 男 | 1971-10-01 | | 2 | 白云 | 女 | 1972-05-20 | +----+------+------+------------+
mysql> update name set csny='1971-01-10' where xm='张三';
mysql> delete from name where xm='张三';
drop database 库名; drop table 表名;
格式:
grant select on 数据库.* to 用户名@登录主机 identified by "密码"
mysql> grant select,insert,update,delete on *.* to user_1@"%" Identified by "123";
mysql>grant select,insert,update,delete on aaa.* to user_2@localhost identified by "123";
mysql -u user_1 -p -h 192.168.113.50 (-h后跟的是要登录主机的ip地址)
[root@test1 root]# cd /home/data/mysql (进入到库目录,本例库已由val/lib/mysql转到/home/data/mysql,见上述第七部分内容) [root@test1 mysql]# mysqldump -u root -p --opt aaa > back_aaa
[root@test mysql]# mysql -u root -p ccc < back_aaa