mysql常用操作示例

1 下载安装包:
sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2 安装mysql:
yum install mysql mysql-server mysql-libs mysql-server
3 启动mysql服务:
service mysqld start
4 开机启动:
chkconfig mysqld on
5.mysql登入
mysql -u root -p
6.登入后赋予外部ip访问权限
mysql>grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
7.刷新配置,立即生效
mysql>flush privileges; 
8.外部导入sql文件
source /root/jxw.sql

示例sql文件:

drop database jxw;
create database jxw;
use jxw;

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for city
-- ----------------------------
DROP TABLE IF EXISTS `city`;
CREATE TABLE `city` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `state` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT=‘市级信息‘;

-- ----------------------------
-- Records of city
-- ----------------------------
BEGIN;
INSERT INTO `city` VALUES (1, ‘石家庄‘, ‘河北‘);
INSERT INTO `city` VALUES (2, ‘邯郸‘, ‘河北‘);
COMMIT;

相关推荐