一。mysql启动及修改密码
启动
[root@localhost bin]# service mysqld start
Starting MySQL [OK]
[root@localhost bin]# service mysqld stop
Shutting down MySQL. [OK]
[root@localhost bin]# service mysqld restart
MySQL manager or server PID file could not be found! [FAILED]
Starting MySQL. [OK]
登陆
root用户的默认密码是空的,如果已经有密码了,修改时需要加参数-p
[root@localhost bin]# mysqladmin -u root password 123
[root@localhost bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.18-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
进去mysql以后还可以修改密码,
mysql> set password for 'root'@'localhost'=password('1');
Query OK, 0 rows affected (0.01 sec)
mysql> exit;
Bye
注意mysql环境下,命令都需要带;结束。
增加新用户
mysql> grant select,insert,update,delete on *.* to test@localhost identified by "123";
Query OK, 0 rows affected (0.03 sec)
意思是新增一个用户test,密码为123,权限由查询,插入,更新,删除,允许在本地登陆
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
刷新权限
二。mysql数据库方面操作
显示已有数据库列表
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.02 sec)
显示指定数据库中的表
mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
17 rows in set (0.01 sec)
显示表结构
mysql> describe user;
mysql> create database abc; //创建数据库abc
Query OK, 1 row affected (0.01 sec)
mysql> show databases; // 显示现有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| mysql |
| test |
+--------------------+
4 rows in set (0.02 sec)
mysql> use abc; //使用abc数据库
Database changed
mysql> create table a(a1 int(4)); //建立表a1
Query OK, 0 rows affected (0.04 sec)
mysql> drop table a; //删除表
Query OK, 0 rows affected (0.01 sec)
mysql> drop database abc; //删除数据库
Query OK, 1 row affected (0.01 sec)
mysql> delete from a; //清空表
Query OK, 0 rows affected (0.01 sec)
mysql> select * from a;//查询
Empty set (0.00 sec)
mysql>