修改root密码
[root@host]# mysqladmin -u root password "new_password"; #修改root用户密码
服务启停
[root@host]# service mysqld start #启动服务
[root@host]# service mysqld stop #停止服务
用户登陆
[root@host]# mysql -h localhost -u root -p /*命令行登陆方式*/ Enter password:*******
创建数据库(两种方法)
[root@host]# mysql -u root -p /*通过mysql客户端命令创建*/ Enter password:****** mysql> create database db; [root@host]# mysqladmin -u root -p create db; /*通过mysqladmin在shell环境中创建,可非root用户创建*/ mysql> drop database db; /*删除创建的数据库*/ [root@host]# mysqladmin -u root -p drop db
创建用户(表添加或'create user ...'添加)
mysql> insert into user (host,user,password,select_priv,insert_priv,update_priv) values('localhost','user',password('password'),'Y','Y','Y'); mysql> flush privileges; mysql> select host,user,select_priv,insert_priv,update_priv from user; +-----------+-------------+-------------+-------------+-------------+ | host | user | select_priv | insert_priv | update_priv | +-----------+-------------+-------------+-------------+-------------+ | localhost | root | Y | Y | Y | | % | root | Y | Y | Y | | localhost | user | Y | Y | Y | +-----------+-------------+-------------+-------------+-------------+ mysql>
数据库和表应用
mysql> show databases; /*显示当前用户下可用的数据库实例*/ +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ mysql> use mysql /*使用'mysql'数据库实例*/ Database changed mysql> select database(); #查看当前使用的数据库实例 +------------+ | database() | +------------+ | mysql | +------------+ mysql> show tables; #显示当前数据库可用的表 +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | ...省略... | | user | +---------------------------+ mysql> desc user; /*查看数据库的结构信息*/ +------------------------+-----------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------------------+------+-----+---------+-------+ | Host | char(60) | NO | PRI | | | | User | char(16) | NO | PRI | | | | Password | char(41) | NO | | | | | ...省略... | ...省略... | ... | | ... | | +------------------------+-----------------------------------+------+-----+---------+-------+查询使用实例
mysql> select host,user,password from user; /*select查询使用实例*/ mysql>