基础入门
============管理MySQL==========
1.查看MySQL版本
mysqladmin --version
2.启动MySQL
/etc/init.d/mysqld start
mysqld_safe &
3.刚安装好后的MySQL,先修改密码
mysqladmin -u root password "new_password";
4.登录MySQL
[root@node0 ~]# mysql -uroot -p
Enter password:
5.查看库
show DATABASES;
6.关闭MySQL
/etc/init.d/mysqld stop
[root@node0 ~]# mysqladmin -uroot -p shutdown
Enter password:
=========查MySQL信息=============
1.查看MySQL是否启动
ps -ef|grep mysqld
lsof -i:3306
2.查看库
mysql> show DATABASES;
3.进入库
mysql> use 库名;
4.查看表
mysql> show TABLES;
5.显示数据表的属性,属性类型,主键信息 ,是否为 NULL,默认值等其他信息。
mysql> SHOW COLUMNS FROM 表名;
6.显示数据表的详细索引信息,包括PRIMARY KEY(主键)。
mysql> SHOW INDEX FROM 表名;
7.输出Mysql数据库管理系统的性能及统计信息,G按列输出。
mysql> SHOW TABLE STATUS FROM 库名G;
===============表操作=============
1.创建库
mysql> create DATABASE STUDENTS;
2.创建表
mysql> create table students ( id int not NULL auto_increment primary key, name char(8) not null, sex char(4) not null, age tinyint unsigned not NULL, tel char(13) NULL default "-" );
3.显示表属性,id为主键,自增。
mysql> SHOW COLUMNS FROM students;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(8) | NO | | NULL | |
| sex | char(4) | NO | | NULL | |
| age | tinyint(3) unsigned | NO | | NULL | |
| tel | char(13) | YES | | - | |
+-------+---------------------+------+-----+---------+----------------+
4.插入数据
mysql> insert into students(name,sex,age,tel) values("Tom","Man",17,"15523232632");
5.查看表数据
mysql> select * from students;
6.修改表数据
mysql> update students set name="Tim" where id=1;
==========授权==================
1.授权远程192.168.31.0/24网段以test用户登录拥有STUDENTS库的所有操作权限。
mysql> grant all on STUDENTS.* to test@"192.168.31.%" identified by 'test';
mysql> flush privileges;
2.远程登录:
mysql -h 192.168.31.100 -utest -ptest