mysql 终端命令
1、打开数据库
/usr/local/MySQL/bin/mysql -u root -p
2、输入root密码
3、使用我的数据库
use mysql
4、查看表
desc table_name
5、查看端口号
show global variables like 'port'
6、创建表
CREATE TABLE t1(
id int not null,
name char(20)
);
CREATE TABLE t1(
id int not null primary key,
name char(20)
);
CREATE TABLE t1(
id int not null,
name char(20),
primary key (id,name)
);
CREATE TABLE t1(
id int not null default 0 primary key,
name char(20) default '1'
);
7、开启远程访问:
use mysql;
update user set host = “%” where user = “root”;
flush privileges;
8、关闭远程访问:
use mysql;
update user set host = “localhost” where user = “root” and host= “%”;
flush privileges;
9、启动MySQL服务
sudo /usr/local/MySQL/support-files/mysql.server start
10、停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server stop
11、重启MySQL服务
sudo /usr/local/mysql/support-files/mysql.server restart