服务:
# chkconfig --list 列出所有系统服务
# chkconfig --list | grep on 列出所有启动的系统服务# chkconfig --list mysqld
# whereis mysql 查看文件安装路径
# which mysql 查询运行文件所在路径(文件夹地址)usr/bin/mysql 是指:mysql的运行路径var/lib/mysql 是指:mysql数据库文件的存放路径usr/lib/mysql 是指:mysql的安装路径
添加环境变量:
# vi /etc/profile
# export MYSQL_HOME=/usr/local/mysql# export PATH=$PATH:$MYSQL_HOME/bin
1.数据库指令:
# service mysqld start 启动MySQL
# service mysqld restart 重启MySQL# service mysqld stop 停止MySQL
2.进入MySQL表单操作
# -u root -p /mysql -h localhost -u root -p DatabaseName; 进入MySQL
MySQL> show databases; 列出数据库 MySQL> create database XXX; 创建数据库XXXMySQL> use databaseName; 使用数据库databaseName
MySQL> show tables; 列出表单MySQL> create table mytablename (ID int auto_increment not null primary key,usename varchar(20),password varchar(64),sex varchar(10),address varchar(20)); 创建表单
MySQL> drop table mytablename ; 删除表单MySQL> drop database databasename; 删除数据库
3.增删改查
MySQL> insert into mytablename values('','zhangsan','123456','fomale','guiyanag'); 插入
MySQL> select * from mytablename ; 查找验证结果
MySQL> select * from mytablename where ID = '1'; 精准查找MySQL> update mytablename set address = 'shanghai' where username = 'zhangsan'; 修改zhangsan的address为shanghai
MySQL> delete from mytablename where ID = '1'; 删除记录
新增万能用户
grant select On database.* to identity by 'password'
用户名user_1 密码是123456
可以自任何PC上登录这个用户对数据库操作
MySQL> grant select,insert update,delete on *.* to " identity by "123456";
创建只有在本机才能操作数据库的用户
用户名user_2 密码是123456
MySQL> grant select,insert update,delete on *.* to identity by "123456";
登录数据库库
MySQL> -u user_1 -p -h IP地址;
另外附上常用的一些命令我列一下仅供参考:
其它的mysql数据库相关的操作如下
(1) 创建数据库TestDB mysql> create database TestDB;
(2) 制定TestDB数据库为当前默认数据库 mysql> use TestDB; (3) 在TestDB数据库中创建表customers mysql> create table customers(userid int not null, username varchar(20) not null); (4) 显示数据库列表 mysql> show databases; (5)显示数据库中的表 mysql> show tables; (6)删除表customers mysql> drop table customers; (7)显示customers表的结构 mysql> desc customers; (8) 向customers表中插入一条记录 mysql> insert into customers(userid, username) values(1, 'hujiahui'); (9) 让操作及时生效; mysql> commit; (10) 查询customers中的记录 mysql> select * from customers; (11) 更新表中的数据 mysql> update customers set username='DennisHu' where userid=1; (12) 删除表中的记录 mysql> delete from customers; (13)授予likui用户访问数据库的权限 # grant select, insert, update, delete on *.* to likui@localhost indentified by "123456";