linux mysql etc inid_Linux下mysql基本操作
Linux下mysql基本操作
作者:浩浩哥来了
对mysql进行初始密码的添加
方法(一)
mysqladmin -uroot password 123
方法(二)
如果在添加初始密码是报错了可以进行我下面的方法修改密码。
ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
在/etc/my.cnf文件中添加skip-grant-tables
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
user=mysql
# Disabling symbolic-links is recommendedto prevent assorted security risks
symbolic-links=0
重启mysqld
[root@luowenhao ~]# /etc/init.d/mysqldrestart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
使用/usr/bin/mysql进入数据库
/usr/bin/mysql
进入mysql数据库中修改user表中root的密码
mysql>use mysql;
Readingtable information for completion of table and column names
You canturn off this feature to get a quicker startup with –A
对root用户进行添加新密码为new-password
mysql>update user set password=password('new-password')where user='root';
Query OK,3 rows affected (0.00 sec)
Rowsmatched: 3 Changed: 3 Warnings: 0
在/etc/my.cnf文件中删除skip-grant-tables
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommendedto prevent assorted security risks
symbolic-links=0
重启mysqld
[root@luowenhao ~]# /etc/init.d/mysqldrestart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
使用new-password这个密码进行登录
mysql-uroot -p
Enterpassword:
现在可以使用此命令修改密码为123
mysqladmin-uroot -pnew-password password 123
对mysql进行登录
[root@luowenhao ~]# mysql -uroot –p 登录为root用户
Enter password: 输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.
This software comes with ABSOLUTELY NOWARRANTY. This is free software,
and you are welcome to modify andredistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql> 如果出现了这样的标志恭喜你进入了mysql数据库
显示数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| lwh |
| mysql |
+--------------------+
3 rows in set (0.00 sec)
创建luowenhao这个数据库
mysql> create database luowenhao;
Query OK, 1 row affected (0.00 sec)
删除数据库
mysql> drop database luowenhao;
Query OK, 0 rows affected (0.01 sec)
进入数据库
mysql> use mysql;
Database changed
显示表信息
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.01 sec)
创建表
mysql> create table name(
-> id int auto_increment not null primary key ,
-> uname char(8),
-> gender char(2),
-> birthday date );
Query OK, 0 rows affected (0.03 sec)
显示表结构
mysql> describe lwh;
+----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default |Extra |
+----------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| uname | char(8) | YES | | NULL | |
| gender | char(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
+----------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
在表中插入数据
mysql> insert intolwh(uname,gender,birthday) values('zhangsan','nv','1929-05-21');
Query OK, 1 row affected (0.00 sec)
在表中更新数据
mysql> update lwh setbirthday='1930-06-05' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
列举表中信息
mysql> select * from lwh;
+----+----------+--------+------------+
| id | uname | gender | birthday |
+----+----------+--------+------------+
| 1| zhangsan | nv | 1930-06-05 |
+----+----------+--------+------------+
1 row in set (0.00 sec)
导出数据库之前查看数据库的编码方式
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
character_set_client为客户端编码方式;character_set_connection为建立连接使用的编码;character_set_database数据库的编码;character_set_results结果集的编码;只要保证以上四个采用的编码方式一样,就不会出现乱码问题。character_set_server数据库服务器的编码;
再进行数据库导出
[root@luowenhao ~]# mysqldump -uroot -p lwh> /lwh.sql
Enter password:
数据库导入(一)
首先设置编码
mysql> set name utf8;
ERROR 1193 (HY000): Unknown system variable'name'
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)
创建相同名称的数据库
mysql> create database lwh;
Query OK, 1 row affected (0.00 sec)
进入数据库同时确定当前数据库是不存在数据
mysql> use lwh;
Database changed
mysql> show tables;
Empty set (0.00 sec)
导入数据并查看表
mysql> source /lwh.sql;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.07 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_lwh |
+---------------+
| lwh |
+---------------+
1 row in set (0.00 sec)
数据库导入(二)
[root@luowenhao ~]# mysql -uroot -p lwh
Enter password:
进入数据库查看
[root@luowenhao ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.
This software comes with ABSOLUTELY NOWARRANTY. This is free software,
and you are welcome to modify andredistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
进入lwh数据库
mysql> use lwh;
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
查看表
mysql> show tables;
+---------------+
| Tables_in_lwh |
+---------------+
| lwh |
+---------------+
1 row in set (0.00 sec)
创建一个test用户,密码位test,“%“代表联网中的所有用户都能用test用户名访问数据库(所有数据库中的所有表);
grant all on *.* to 'test'@'%' identifiedby 'test';
并将/etc/mysql/mysql.cnf中的bind-address一行注释
访问a_b中的所有表,用如下语句实现
grant all on a_b.* to 'test'@'%'identified by 'test';
限制权限,限制test用户只能查询a_b中的所有表
grant select on a_db.* to 'test'@'%'identified by 'test';
查看mysql中的所有数据库用户
select distinct concat('User:''',user,'''@''',host,''';') as query from mysql.user;
删除test用户
delete from user where User='test' andHost='%';
flush privileges;
linux mysql etc inid_Linux下mysql基本操作相关推荐
- mysql5.7.17.zip教程,Mysql学习win10下mysql 5.7.17 zip压缩包版安装教程
搜索热词 <MysqL学习win10下MysqL 5.7.17 zip压缩包版安装教程>要点: 本文介绍了MysqL学习win10下MysqL 5.7.17 zip压缩包版安装教程,希望对 ...
- ubuntu删除安装的mysql数据库_Ubuntu下MySQL数据库安装与配置与卸载
安装: sudo apt-get install mysql-server mysql-client 一旦安装完成,MySQL 服务器应该自动启动.您可以在终端提示符后运行以下命令来检查 MySQL ...
- linux下mysql授权_linux下mysql命令(用户授权、数据导入导出)
1,linux下启动mysql的命令: 复制代码 代码示例: mysqladmin start /ect/init.d/mysql start (前面为mysql的安装路径) 2,linux下重启my ...
- linux mysql 事务_linux下mysql Insert update delete 事务 用户管理
linux下mysql Insert update delete 事务 用户管理 1.INSERT插入语句格式: INSERT INTO tb_name (字段1, 字段2, ...) VALUES ...
- linux重新安装mysql步骤_Linux下MySQL安装及相关操作过程
一.安装MySQL数据库,但是前提是已经安好Linux系统,我使用的是Red hat desktop 6.0 SP1,系统盘的Tools里面有相应的软件,为5.0系列,但经测试无法使用,不能正常运行, ...
- linux安装mysql字符_Linux下MySQL的彻底卸载和安装配置字符集
前言: Linux环境下MySQL的安装和配置在网上已经有很多教程了.之所以写这篇文章是因为在配置字符集的时候找了网上的一些教程发现并不能用导致折腾了一阵子.下面的教程均是亲自实践. MySQL的彻底 ...
- linux删除mysql临时文件_linux下mysql自动备份数据库与自动删除临时文件_MySQL
bitsCN.com linux下mysql自动备份数据库与自动删除临时文件 一.每日23:00自动删除临时文件 首先查看一下crontab的任务列表:crontab -l然后新建:crontab - ...
- linux mysql 临时文件_linux下mysql自动备份数据库与自动删除临时文件
一.每日23:00自动删除临时文件 首先查看一下crontab的任务列表: crontab -l 然后新建: crontab -e 添加一行: 00 03 * * * rm -rf /www/cmst ...
- linux下mysql乱码_linux下mysql中文乱码
登录mysql执行 mysql> show variables like 'character%'; 发现编码有些不是utf-8 修改/etc/mysql/my.cnf,网上说的是/etc/my ...
最新文章
- 杨辉三角(下三角或者等腰三角)
- CentOS 6.5系统安装配置图解教程(详细图文)
- 【Linux 线程】常用线程函数复习《三》
- 计算机陕西高校保研排名,陕西18所大学2021届保研率排行榜
- BZOJ 1180: [CROATIAN2009]OTOCI [LCT]
- 有关于类的定义赋值与调用总结
- 关于男生追女生的数学模型【转王博】
- 武汉大学953计算机综合真题,武大电力系统分析实验报告.docx
- php excel导出柱状图,YII2框架下使用PHPExcel导出柱状图
- 模拟大规模电动车充电行为(Matlab实现)
- 内存(主存)(一般指电脑内存条)包含RAM(SRAM,DRAM),ROM,高速缓存(CACHE),SDRAM,DDRRAM
- 联想笔记本e43l_联想昭阳e43l
- 如何更改HomePod使用的Apple ID?
- ORACLE学习笔记-CentOS 7.2 Oracle 12C R2安装部署
- ISCC2017 Misc write up附件题目文件
- 聚类算法之K-Means,K-Means++,elkan K-Means和MiniBatch K-Means算法流程
- MySQL 必知必会系列(一)
- 关于Qt4K高分屏自适应问题
- 如何从初级程序员顺利晋升到高级程序员?
- ETL工具KETTLE常用设计之——作业设计思路模板