服务:
# 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; 创建数据库XXX
MySQL> 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 username@localhost identity by 'password'
用户名user_1 密码是123456
可以自任何PC上登录这个用户对数据库操作
MySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456";
创建只有在本机才能操作数据库的用户
用户名user_2 密码是123456
MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456";
登录数据库库
MySQL> -u user_1 -p -h IP地址;