MySQL常用操作

Win7登陆MySQL数据库进入目录:cd 安装目录\bin后,执行命令mysqld -install安装mysql服务,服务安装成功后,执行net start mysql命令启动Mysql服务。
输入:mysql -u root -p 密码:xxxx

这时报错pymysql.err.OperationalError: (1045, u"Access denied for user 'root'@'localhost' (using password: No)")

最简单的方法是更换了root密码的认证方式解决的,新版mysql使用的caching_sha2_password,换成mysql_native_password我就可以连上了。

步骤是在cmd命令行连接mysql, 通过mysql -u root -p

然后输入ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root456';

这时再跑下python脚本就可以连接了。

创建数据库:create database 数据库名;

删除数据库:drop database 数据库名;

查看所有数据库:show databases;

选择数据库:use 数据库名;

查看数据表:show tables;

查看数据表中所有的数据:select * from 表名;

查看数据表的表结构:descirbe 表名;

显示表中的列:show columns from 表名;

有条件地从表中选取数据,可将 where 子句添加到 select 语句中

例如:select * from runoob_tbl where runoob_author='菜鸟教程';

向表中插入数据:
1、insert into 表名(列名1,列名2,...) values("列值1","列值2",...);
2、insert into 表名 values("列值1","列值2",...);

限制查询结果(limit):
只查询前x条记录:select * from 表名 limit x;
查询从x条记录开始的第y条记录:
select * from 表名 limit x,y;

创建数据表:CREATE TABLE 数据表名 (column_name column_type);

删除数据表:DROP TABLE 数据表名;

数据表插入数据:INSERT INTO table_name ( field1, field2,...fieldN );

数据库中查询数据:SELECT * from table_name;

获取数据表结构:desc table_name;或show columns from table_name;

 

Linux下查看MySQL字符集

Linux系统下:

[hadoop@hadoop000 Desktop]$ mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

1.通过mysql -uroot -proot登陆后

mysql> show variables like 'chara%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>

posted @ 2019-02-25 12:28  烽火连城516  阅读(163)  评论(0编辑  收藏  举报