mysql安装以及配置外网权限(win)

1.下载地址:https://dev.mysql.com/downloads/mysql/
在这里插入图片描述
默认是最新的版本,如果需要其他版本选择Archives,笔者选择了比较稳定的mysql5.7系列的产品线。选择原因是适配公司产品的pyqt5控件的需要,此处略去四个字…
在这里插入图片描述
这是一个64位的bin目录的安装包,即不需要繁琐的安装过程,通过配置命令以及环境变量即可在终端中搞事情,对于开发来说想想都开心。至于为什么我来整理这个文档,此处略去四个字…
so…闲话不多,我们来搞事情!
2.安装
下载完毕后的,解压出来是这个样子的
下载完毕后,解压出来,如果你发现没有my.ini这个配置文件,不要懵逼,自己创建一个,以下是笔者的配置。

# Other default tuning values
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory 
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option 
# "--defaults-file". 
#
# To run run the server from the command line, execute this in a 
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# To install the server as a Windows service manually, execute this in a 
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
[client]
# socket=0.0
port=3306

[mysql]
no-beep
default-character-set=utf8


# SERVER SECTION
# ----------------------------------------------------------------------
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this file.
# server_type=3
[mysqld]
tmp_table_size = 512M
max_heap_table_size = 512M


# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking

# enable-named-pipe

# shared-memory

# shared-memory-base-name=MYSQL

# The Pipe the MySQL Server will use
# socket=MYSQL

# The TCP/IP Port the MySQL Server will listen on
port=3306
bind-address=0.0.0.0

# Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/softs/mysql-5.7.23-winx64"

# Path to the database root
datadir=C:/softs/mysql-5.7.23-winx64/data

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# Enable Windows Authentication
# plugin-load=authentication_windows.dll

# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="DESKTOP-JU9QT3C.log"
slow-query-log=1
slow_query_log_file="DESKTOP-JU9QT3C-slow.log"
long_query_time=10

# Binary Logging.
# log-bin

# Error Logging.
log-error="DESKTOP-JU9QT3C.err"

# Server Id.
server-id=1

# Secure File Priv.
secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.7/Uploads"

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=151

# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=0

# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_open_cache=2000

# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=101M

# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before.  This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=10

#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method.  This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=193M

# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=8M

# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K

#*** INNODB Specific options ***
# innodb_data_home_dir=0.0

# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
# skip-innodb

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system.  Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=8M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=48M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=9

# The increment size (in MB) for extending the size of an auto-extend InnoDB system tablespace file when it becomes full.
innodb_autoextend_increment=64

# The number of regions that the InnoDB buffer pool is divided into.
# For systems with buffer pools in the multi-gigabyte range, dividing the buffer pool into separate instances can improve concurrency,
# by reducing contention as different threads read and write to cached pages.
innodb_buffer_pool_instances=8

# Determines the number of threads that can enter InnoDB concurrently.
innodb_concurrency_tickets=5000

# Specifies how long in milliseconds (ms) a block inserted into the old sublist must stay there after its first access before
# it can be moved to the new sublist.
innodb_old_blocks_time=1000

# It specifies the maximum number of .ibd files that MySQL can keep open at one time. The minimum value is 10.
innodb_open_files=300

# When this variable is enabled, InnoDB updates statistics during metadata statements.
innodb_stats_on_metadata=0

# When innodb_file_per_table is enabled (the default in 5.6.6 and higher), InnoDB stores the data and indexes for each newly created table
# in a separate .ibd file, rather than in the system tablespace.
innodb_file_per_table=1

# Use the following list of values: 0 for crc32, 1 for strict_crc32, 2 for innodb, 3 for strict_innodb, 4 for none, 5 for strict_none.
innodb_checksum_algorithm=0

# The number of outstanding connection requests MySQL can have.
# This option is useful when the main MySQL thread gets many connection requests in a very short time.
# It then takes some time (although very little) for the main thread to check the connection and start a new thread.
# The back_log value indicates how many requests can be stacked during this short time before MySQL momentarily
# stops answering new requests.
# You need to increase this only if you expect a large number of connections in a short period of time.
back_log=80

# If this is set to a nonzero value, all tables are closed every flush_time seconds to free up resources and
# synchronize unflushed data to disk.
# This option is best used only on systems with minimal resources.
flush_time=0

# The minimum size of the buffer that is used for plain index scans, range index scans, and joins that do not use
# indexes and thus perform full table scans.
join_buffer_size=256K

# The maximum size of one packet or any generated or intermediate string, or any parameter sent by the
# mysql_stmt_send_long_data() C API function.
max_allowed_packet=4M

# If more than this many successive connection requests from a host are interrupted without a successful connection,
# the server blocks that host from performing further connections.
max_connect_errors=100

# Changes the number of file descriptors available to mysqld.
# You should try increasing the value of this option if mysqld gives you the error "Too many open files".
open_files_limit=4161

# Set the query cache type. 0 for OFF, 1 for ON and 2 for DEMAND.
query_cache_type=0

# If you see many sort_merge_passes per second in SHOW GLOBAL STATUS output, you can consider increasing the
# sort_buffer_size value to speed up ORDER BY or GROUP BY operations that cannot be improved with query optimization
# or improved indexing.
sort_buffer_size=256K

# The number of table definitions (from .frm files) that can be stored in the definition cache.
# If you use a large number of tables, you can create a large table definition cache to speed up opening of tables.
# The table definition cache takes less space and does not use file descriptors, unlike the normal table cache.
# The minimum and default values are both 400.
table_definition_cache=1400

# Specify the maximum size of a row-based binary log event, in bytes.
# Rows are grouped into events smaller than this size if possible. The value should be a multiple of 256.
binlog_row_event_max_size=8K

# If the value of this variable is greater than 0, a replication slave synchronizes its master.info file to disk.
# (using fdatasync()) after every sync_master_info events.
sync_master_info=10000

# If the value of this variable is greater than 0, the MySQL server synchronizes its relay log to disk.
# (using fdatasync()) after every sync_relay_log writes to the relay log.
sync_relay_log=10000

# If the value of this variable is greater than 0, a replication slave synchronizes its relay-log.info file to disk.
# (using fdatasync()) after every sync_relay_log_info transactions.
sync_relay_log_info=10000

# Indicates how is the InnoDB Cluster configured as (Classic, Sandbox, Master or Slave).
# innodbclustertypeselection=ClassicMySQLReplication

# Indicates how is the InnoDB Cluster is/will be named.
# innodbclustername="sandboxCluster"

# Indicates how many instances will the InnoDB cluster sandbox will have.
# innodbclusterinstances=0

# Holds the InnoDB Cluster Username.
# innodbclusterusername

# Indicates the InnoDB Cluster URI.
# innodbclusteruri

# Indicates the InnoDB Cluster Port.
# innodbclusterport=3306

# Load mysql plugins at start."plugin_x ; plugin_y".
# plugin_load

# MySQL server's plugin configuration.
# loose_mysqlx_port=33060

其实配置文件里,前段的注释内容已经声明了,如何安装与配置了。此处只是提几个重要的配置,比如需要外网以及预设内存。没有的目录创建即可,比如以下的data,是笔者创建来管理与存放数据的。

[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
# 监听0.0.0.0,以允许其他主机访问
bind-address=0.0.0.0
# mysql安装包的绝对路径
basedir="C:/softs/mysql-5.7.23-winx64"
# 创表创库或是初始化mysql时,生成的数据存放目录
datadir=C:/softs/mysql-5.7.23-winx64/data
 #设置内存表最大限制
max_heap_table_size =1024M 
# 设置内存临时表的最大限制
tmp_table_size =1024M
#指定当数据超过临时表的最大值设定时,自动转为基于磁盘表的时候所用的引擎,innodb或者myisam
internal_tmp_disk_storage_engine = INNODB
#指定当内存表数据超过临时表的最大值设定时,转存到磁盘时的路径。
tmpdir=C:/softs/mysql-5.7.23-winx64/data/temp

配置环境变量
在这里插入图片描述
按照上面的步骤,将解压后的mysql安装包的bin目录添加到环境变量,这样就可以在任意终端中操作mysql的命令。如果实在懒,那么久跑安装包的bin目录下去操作吧。但是笔者建议你善良,举手之劳,会让后来者感激不尽的。
----------------------------------来了-----------------------------------
一、卸载旧版本mysql
如果新的服务器不幸被人"糟蹋"过,而你的开发版本驱动又不能兼容高的版本或者更高,或者你就任性地喜欢mysql5.7.1,那么就干掉旧的版本。
1.如果是exe安装的,或许会有很多其他插件绑定安装了,移步控制面板,清空相关的软件即可
2.如果原本就是bin安装的,而你又不知道是谁的老婆,建议先不要删(shang),可是我们还得搞事情

# 先停止mysql
net stop mysql
# 移除mysql的注册服务
sc delete mysql

嗯嗯…世界都安静…
二、初始化mysql
1.执行初始化命令,可以指定配置文件路径,如果不指定,mysql会优先查找根目录下的my.ini文件

mysqld --initialize --user=mysql --console

在这里插入图片描述
执行完毕后终端会生成一个临时的密码,请记住它,方便后面的登录
2.接着就是执行安装的命令

mysqld install

如果出现了Install/Remove of the Service Denied!的错误,那么请使用管理员的身份进行安装。点击搜索栏,右击命令提示符即可。
在这里插入图片描述
友好提示你successfully,就说明你成功了
在这里插入图片描述
3.启动mysql服务

net start mysql

在这里插入图片描述
4.登录mysql
在这里插入图片描述
用上面的临时密码,登录即可,如果你不幸关闭了终端,清空data文件夹,重复以上步骤,重新初始化即可。至于其他跳过认证骚操作就不去玩了,坚持linux的哲学:简单至上!
5.修改初始密码

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;

6.配置外网访问权限

mysql>use mysql;
mysql>update user set host = '%' where user ='root'; 
mysql>select host from user where user='root'; 
mysql>flush privileges;

7.重启mysql服务

net stop mysql
nte start mysql

嗯嗯,至此,mysql的安装配置已经完毕了。关于多实例配置以及读写分离的配置,这里不再提了,始终还是不喜欢win系统。
三、pyqt5使用mysql
虽然重写的版本已经不再依赖了,但是遇到的问题也暂行记录一下。
将安装中的lib目录下的libmysql.dll拷到python环境的pyqt5的模块包下即可。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MYSQL常用命令 1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql 3.导出一个数据库结构 mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql -d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table 4.导入数据库 A:常用source 命令 进入mysql数据库控制台, 如mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source wcnc_db.sql B:使用mysqldump命令 mysqldump -u username -p dbname < filename.sql C:使用mysql命令 mysql -u username -p -D dbname 2、退出MySQL:quit或exit 二、库操作 1、、创建数据库 命令:create database 例如:建立一个名为xhkdb的数据库 mysql> create database xhkdb; 2、显示所有的数据库 命令:show databases (注意:最后有个s) mysql> show databases; 3、删除数据库 命令:drop database 例如:删除名为 xhkdb的数据库 mysql> drop database xhkdb; 4、连接数据库 命令: use 例如:如果xhkdb数据库存在,尝试存取它: mysql> use xhkdb; 屏幕提示:Database changed 5、查看当前使用的数据库 mysql> select database(); 6、当前数据库包含的表信息: mysql> show tables; (注意:最后有个s) 三、表操作,操作之前应连接某个数据库 1、建表 命令:create table ( [,.. ]); mysql> create table MyClass( > id int(4) not null primary key auto_increment, > name char(20) not null, > sex int(4) not null default '0', > degree double(16,2)); 2、获取表结构 命令: desc 表名,或者show columns from 表名 mysql>DESCRIBE MyClass mysql> desc MyClass; mysql> show columns from MyClass; 3、删除表 命令:drop table 例如:删除表名为 MyClass 的表 mysql> drop table MyClass; 4、插入数据 命令:insert into [( [,.. ])] values ( 值1 )[, ( 值n )] 例如,往表 MyClass中插入二条记录, 这二条记录表示:编号为1的名为Tom的成绩为96.45, 编号为2 的名为Joan 的成绩为82.99,编号为3 的名为Wang 的成绩为96.5. mysql> insert into MyClass values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang', 96.59); 5、查询表中的数据 1)、查询所有行 命令: select from where 例如:查看表 MyClass 中所有数据 mysql> select * from MyClass; 2)、查询前几行数据 例如:查看表 MyClass 中前2行数据 mysql> select * from MyClass order by id limit 0,2; 或者: mysql> select * from MyClass limit 0,2; 6、删除表中数据 命令:delete from 表名 where 表达式 例如:删除表 MyClass中编号为1 的记录 mysql> delete from MyClass where id=1; 7、修改表中数据:update 表名 set 字段=新值,… where 条件 mysql> update MyClass set name='Mary' where id=1; 7、在表中增加字段: 命令:alter table 表名 add字段 类型 其他; 例如:在表MyClass中添加了一个字段passtest,类型为int(4),默认值为0 mysql> alter table MyClass add passtest int(4) default '0' 8、更改表名: 命令:rename table 原表名 to 新表名; 例如:在表MyClass名字更改为YouClass mysql> rename table MyClass to YouClass; 更新字段内容 update 表名 set 字段名 = 新内容 update 表名 set 字段名 = replace(字段名,'旧内容','新内容'); 文章前面加入4个空格 update article set content=concat('  ',content); 字段类型 1.INT[(M)] 型: 正常大小整数类型 2.DOUBLE[(M,D)] [ZEROFILL] 型: 正常大小(双精密)浮点数字类型 3.DATE 日期类型:支持的范围是1000-01-01到9999-12-31。MySQL以YYYY-MM-DD格式来显示DATE值,但是允许你使用字符串或数字把值赋给DATE列 4.CHAR(M) 型:定长字符串类型,当存储时,总是是用空格填满右边到指定的长度 5.BLOB TEXT类型,最大长度为65535(2^16-1)个字符。 6.VARCHAR型:变长字符串类型 5.导入数据库表    (1)创建.sql文件    (2)先产生一个库如auction.c:mysqlbin>mysqladmin -u root -p creat auction,会提示输入密码,然后成功创建。    (2)导入auction.sql文件    c:mysqlbin>mysql -u root -p auction grant select,insert,delete,create,drop    on *.* (或test.*/user.*/..)    to 用户名@localhost    identified by '密码';    如:新建一个用户帐号以便可以访问数据库,需要进行如下操作:    mysql> grant usage    -> ON test.*    -> TO testuser@localhost;    Query OK, 0 rows affected (0.15 sec)    此后就创建了一个新用户叫:testuser,这个用户只能从localhost连接到数据库并可以连接到test 数据库。下一步,我们必须指定testuser这个用户可以执行哪些操作:    mysql> GRANT select, insert, delete,update    -> ON test.*    -> TO testuser@localhost;    Query OK, 0 rows affected (0.00 sec)    此操作使testuser能够在每一个test数据库中的表执行SELECT,INSERT和DELETE以及UPDATE查询操作。现在我们结束操作并退出MySQL客户程序:    mysql> exit    Bye9! 1:使用SHOW语句找出在服务器上当前存在什么数据库: mysql> SHOW DATABASES; 2:2、创建一个数据库MYSQLDATA mysql> Create DATABASE MYSQLDATA; 3:选择你所创建的数据库 mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!) 4:查看现在的数据库中存在什么表 mysql> SHOW TABLES; 5:创建一个数据库表 mysql> Create TABLE MYTABLE (name VARCHAR(20), sex CHAR(1)); 6:显示表的结构: mysql> DESCRIBE MYTABLE; 7:往表中加入记录 mysql> insert into MYTABLE values ("hyq","M"); 8:用文本方式将数据装入数据库表中(例如D:/mysql.txt) mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE; 9:导入.sql文件命令(例如D:/mysql.sql) mysql>use database; mysql>source d:/mysql.sql; 10:删除表 mysql>drop TABLE MYTABLE; 11:清空表 mysql>delete from MYTABLE; 12:更新表中数据 mysql>update MYTABLE set sex="f" where name='hyq'; 以下是无意中在络看到的使用MySql的管理心得, 摘自:http://www1.xjtusky.com/article/htmldata/2004_12/3/57/article_1060_1.html 在windows中MySql以服务形式存在,在使用前应确保此服务已经启动,未启动可用net start mysql命令启动。而Linux中启动时可用“/etc/rc.d/init.d/mysqld start"命令,注意启动者应具有管理员权限。 刚安装好的MySql包含一个含空密码的root帐户和一个匿名帐户,这是很大的安全隐患,对于一些重要的应用我们应将安全性尽可能提高,在这里应把匿名帐户删除、 root帐户设置密码,可用如下命令进行: use mysql; delete from User where User=""; update User set Password=PASSWORD('newpassword') where User='root'; 如果要对用户所用的登录终端进行限制,可以更新User表中相应用户的Host字段,在进行了以上更改后应重新启动数据库服务,此时登录时可用如下类似命令: mysql -uroot -p; mysql -uroot -pnewpassword; mysql mydb -uroot -p; mysql mydb -uroot -pnewpassword; 上面命令参数是常用参数的一部分,详细情况可参考文档。此处的mydb是要登录的数据库的名称。 在进行开发和实际应用中,用户不应该只用root用户进行连接数据库,虽然使用root用户进行测试时很方便,但会给系统带来重大安全隐患,也不利于管理技术的提高。我们给一个应用中使用的用户赋予最恰当的数据库权限。如一个只进行数据插入的用户不应赋予其删除数据的权限MySql的用户管理是通过 User表来实现的,添加新用户常用的方法有两个,一是在User表插入相应的数据行,同时设置相应的权限;二是通过GRANT命令创建具有某种权限的用户。其中GRANT的常用用法如下: grant all on mydb.* to NewUserName@HostName identified by "password" ; grant usage on *.* to NewUserName@HostName identified by "password"; grant select,insert,update on mydb.* to NewUserName@HostName identified by "password"; grant update,delete on mydb.TestTable to NewUserName@HostName identified by "password"; 若要给此用户赋予他在相应对象上的权限的管理能力,可在GRANT后面添加WITH GRANT OPTION选项。而对于用插入User表添加的用户,Password字段应用PASSWORD 函数进行更新加密,以防不轨之人窃看密码。对于那些已经不用的用户应给予清除,权限过界的用户应及时回收权限,回收权限可以通过更新User表相应字段,也可以使用REVOKE操作。 下面给出本人从其它资料(www.cn-java.com)获得的对常用权限的解释: 全局管理权限: FILE: 在MySQL服务器上读写文件。 PROCESS: 显示或杀死属于其它用户的服务线程。 RELOAD: 重载访问控制表,刷新日志等。 SHUTDOWN: 关闭MySQL服务。 数据库/数据表/数据列权限: Alter: 修改已存在的数据表(例如增加/删除列)和索引。 Create: 建立新的数据库或数据表。 Delete: 删除表的记录。 Drop: 删除数据表或数据库。 INDEX: 建立或删除索引。 Insert: 增加表的记录。 Select: 显示/搜索表的记录。 Update: 修改表中已存在的记录。 特别的权限: ALL: 允许做任何事(和root一样)。 USAGE: 只允许登录--其它什么也不允许做。 --------------------- MYSQL常用命令 有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接MYSQL、修改密码、增加用户等方面来学习一些MYSQL的常用命令。   有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接MYSQL、修改密码、增加用户等方面来学习一些MYSQL的常用命令。     一、连接MYSQL    格式: mysql -h主机地址 -u用户名 -p用户密码      1、例1:连接到本机上的MYSQL   首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>      2、例2:连接到远程主机上的MYSQL   假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令:       mysql -h110.110.110.110 -uroot -pabcd123      (注:u与root可以不用加空格,其它也一样)      3、退出MYSQL命令: exit (回车)   二、修改密码     格式:mysqladmin -u用户名 -p旧密码 password 新密码     1、例1:给root加个密码ab12。首先在DOS下进入目录mysqlbin,然后键入以下命令      mysqladmin -uroot -password ab12      注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。      2、例2:再将root的密码改为djg345   mysqladmin -uroot -pab12 password djg345 MYSQL常用命令(下)   一、操作技巧   1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。也就是说你可以把一个完整的命令分成几行来打,完后用分号作结束标志就OK。   2、你可以使用光标上下键调出以前的命令。但以前我用过的一个MYSQL旧版本不支持。我现在用的是mysql-3.23.27-beta-win。   二、显示命令   1、显示数据库列表。   show databases;   刚开始时才两个数据库:mysql和test。mysql库很重要它里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。   2、显示库中的数据表:   use mysql; //打开库,学过FOXBASE的一定不会陌生吧   show tables;   3、显示数据表的结构:   describe 表名;   4、建库:   create database 库名;   5、建表:   use 库名;   create table 表名 (字段设定列表);   6、删库和删表:   drop database 库名;   drop table 表名;   7、将表中记录清空:   delete from 表名;   8、显示表中的记录:   select * from 表名; 三、一个建库和建表以及插入数据的实例   drop database if exists school; //如果存在SCHOOL则删除   create database school; //建立库SCHOOL   use school; //打开库SCHOOL   create table teacher //建立表TEACHER   (   id int(3) auto_increment not null primary key,   name char(10) not null,   address varchar(50) default '深圳',   year date   ); //建表结束   //以下为插入字段   insert into teacher values('','glchengang','深圳一中','1976-10-10');   insert into teacher values('','jack','深圳一中','1975-12-23');   注:在建表中(1)将ID设为长度为3的数字字段:int(3)并让它每个记录自动加一:auto_increment并不能为空:not null而且让他成为主字段primary key   (2)将NAME设为长度为10的字符字段   (3)将ADDRESS设为长度50的字符字段,而且缺省值为深圳。varchar和char有什么区别呢,只有等以后的文章再说了。   (4)将YEAR设为日期字段。   如果你在mysql提示符键入上面的命令也可以,但不方便调试。你可以将以上命令原样写入一个文本文件中假设为school.sql,然后复制到c:\下,并在DOS状态进入目录\mysql\bin,然后键入以下命令:   mysql -uroot -p密码 school.bbb   注释:将数据库school备份到school.bbb文件,school.bbb是一个文本文件,文件名任取,打开看看你会有新发现。 一.SELECT语句的完整语法为: SELECT[ALL|DISTINCT|DISTINCTROW|TOP] {*|talbe.*|[table.]field1[AS alias1][,[table.]field2[AS alias2][,…]]} FROM tableexpression[,…][IN externaldatabase] [WHERE…] [GROUP BY…] [HAVING…] [ORDER BY…] [WITH OWNERACCESS OPTION] 说明: 用中括号([])括起来的部分表示是可选的,用大括号({})括起来的部分是表示必须从中选择其中的一个。 1 FROM子句 FROM 子句指定了SELECT语句中字段的来源。FROM子句后面是包含一个或多个的表达式(由逗号分开),其中的表达式可为单一表名称、已保存的查询或由 INNER JOIN、LEFT JOIN 或 RIGHT JOIN 得到的复合结果。如果表或查询存储在部数据库,在IN 子句之后指明其完整路径。 例:下列SQL语句返回所有有定单的客户: SELECT OrderID,Customer.customerID FROM Orders Customers WHERE Orders.CustomerID=Customers.CustomeersID 2 ALL、DISTINCT、DISTINCTROW、TOP谓词 (1) ALL 返回满足SQL语句条件的所有记录。如果没有指明这个谓词,默认为ALL。 例:SELECT ALL FirstName,LastName FROM Employees (2) DISTINCT 如果有多个记录的选择字段的数据相同,只返回一个。 (3) DISTINCTROW 如果有重复的记录,只返回一个 (4) TOP显示查询头尾若干记录。也可返回记录的百分比,这是要用 TOP N PERCENT子句(其中N 表示百分比) 例:返回5%定货额最大的定单 SELECT TOP 5 PERCENT* FROM [ Order Details] ORDER BY UnitPrice*Quantity*(1-Discount) DESC 3 用 AS 子句为字段取别名 如果想为返回的列取一个新的标题,或者,经过对字段的计算或总结之后,产生了一个新的值,希望把它放到一个新的列里显示,则用AS保留。 例:返回FirstName字段取别名为NickName SELECT FirstName AS NickName ,LastName ,City FROM Employees 例:返回新的一列显示库存价值 SELECT ProductName ,UnitPrice ,UnitsInStock ,UnitPrice*UnitsInStock AS valueInStock FROM Products 二 .WHERE 子句指定查询条件 1 比较运算符 比较运算符 含义 = 等于 > 大于 = 大于等于 <= 小于等于 不等于 !> 不大于 !#1/1/96# AND OrderDate#96-1-1# 也可以表示为: WHERE OrderDate>Datevalue(‘1/1/96’) 使用 NOT 表达式求反。 例:查看96年1月1日以后的定单 WHERE Not OrderDateQuantity 另一种方法是用 Microsof JET SQL 独有的 JNNER JOIN 语法: FROM table1 INNER JOIN table2 ON table1.field1 comparision table2.field2 其中comparision 就是前面WHERE子句用到的比较运算符。 SELECT FirstName,lastName,OrderID,CustomerID,OrderDate FROM Employees INNER JOIN Orders ON Employees.EmployeeID=Orders.EmployeeID 注意: INNER JOIN不能连接Memo OLE Object Single Double 数据类型字段。 在一个JOIN语句中连接多个ON子句 语法: SELECT fields FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field1 AND ON table1.field2 compopr table2.field2 OR ON table1.field3 compopr table2.field3 也可以 SELECT fields FROM table1 INNER JOIN (table2 INNER JOIN [( ]table3 [INNER JOER] [( ]tablex[INNER JOIN] ON table1.field1 compopr table2.field1 ON table1.field2 compopr table2.field2 ON table1.field3 compopr table2.field3 部连接返回更多记录,在结果中保留不匹配的记录,不管存不存在满足条件的记录都要返回另一侧的所有记录。 FROM table [LEFT|RIGHT]JOIN table2 ON table1.field1comparision table.field2 用左连接来建立部连接,在表达式的左边的表会显示其所有的数据 例:不管有没有定货量,返回所有商品 SELECT ProductName ,OrderID FROM Products LEFT JOIN Orders ON Products.PrductsID=Orders.ProductID 右连接与左连接的差别在于:不管左侧表里有没有匹配的记录,它都从左侧表中返回所有记录。 例:如果想了解客户的信息,并统计各个地区的客户分布,这时可以用一个右连接,即使某个地区没有客户,也要返回客户信息。 空值不会相互匹配,可以通过连接才能测试被连接的某个表的字段是否有空值。 SELECT * FROM talbe1 LEFT JOIN table2 ON table1.a=table2.c 1 连接查询中使用Iif函数实现以0值显示空值 Iif表达式: Iif(IsNull(Amount,0,Amout) 例:无论定货大于或小于¥50,都要返回一个标志。 Iif([Amount]>50,?Big order?,?Small order?) 五. 分组和总结查询结果 在SQL的语法里,GROUP BY和HAVING子句用来对数据进行汇总。GROUP BY子句指明了按照哪几个字段来分组,而将记录分组后,用HAVING子句过滤这些记录。 GROUP BY 子句的语法 SELECT fidldlist FROM table WHERE criteria [GROUP BY groupfieldlist [HAVING groupcriteria]] 注:Microsoft Jet数据库 Jet 不能对备注或OLE对象字段分组。 GROUP BY字段中的Null值以备分组但是不能被省略。 在任何SQL合计函数中不计算Null值。 GROUP BY子句后最多可以带有十个字段,排序优先级按从左到右的顺序排列。 例:在‘WA’地区的雇员表中按头衔分组后,找出具有同等头衔的雇员数目大于1人的所有头衔。 SELECT Title ,Count(Title) as Total FROM Employees WHERE Region = ‘WA’ GROUP BY Title HAVING Count(Title)>1 JET SQL 中的聚积函数 聚集函数 意义 SUM ( ) 求和 AVG ( ) 平均值 COUNT ( ) 表达式中记录的数目 COUNT (* ) 计算记录的数目 MAX 最大值 MIN 最小值 VAR 方差 STDEV 标准误差 FIRST 第一个值 LAST 最后一个值 六. 用Parameters声明创建参数查询 Parameters声明的语法: PARAMETERS name datatype[,name datatype[, …]] 其中name 是参数的标志符,可以通过标志符引用参数. Datatype说明参数的数据类型. 使用时要把PARAMETERS 声明置于任何其他语句之前. 例: PARAMETERS[Low price] Currency,[Beginning date]datatime SELECT OrderID ,OrderAmount FROM Orders WHERE OrderAMount>[low price] AND OrderDate>=[Beginning date] 七. 功能查询 所谓功能查询,实际上是一种操作查询,它可以对数据库进行快速高效的操作.它以选择查询为目的,挑选出符合条件的数据,再对数据进行批处理.功能查询包括更新查询,删除查询,添加查询,和生成表查询. 1 更新查询 UPDATE子句可以同时更改一个或多个表中的数据.它也可以同时更改多个字段的值. 更新查询语法: UPDATE 表名 SET 新值 WHERE 准则 例:英国客户的定货量增加5%,货运量增加3% UPDATE OEDERS SET OrderAmount = OrderAmount *1.1 Freight = Freight*1.03 WHERE ShipCountry = ‘UK’ 2 删除查询 DELETE子句可以使用户删除大量的过时的或冗于的数据. 注:删除查询的对象是整个记录. DELETE子句的语法: DELETE [表名.*] FROM 来源表 WHERE 准则 例: 要删除所有94年前的定单 DELETE * FROM Orders WHERE OrderData<#94-1-1# 3 追加查询 INSERT子句可以将一个或一组记录追加到一个或多个表的尾部. INTO 子句指定接受新记录的表 valueS 关键字指定新记录所包含的数据值. INSERT 子句的语法: INSETR INTO 目的表或查询(字段1,字段2,…) valueS(数值1,数值2,…) 例:增加一个客户 INSERT INTO Employees(FirstName,LastName,title) valueS(‘Harry’,’Washington’,’Trainee’) 4 生成表查询 可以一次性地把所有满足条件的记录拷贝到一张新表中.通常制作记录的备份或副本或作为报表的基础. SELECT INTO子句用来创建生成表查询语法: SELECT 字段1,字段2,… INTO 新表[IN 部数据库] FROM 来源数据库 WHERE 准则 例:为定单制作一个存档备份 SELECT * INTO OrdersArchive FROM Orders 八. 联合查询 UNION运算可以把多个查询的结果合并到一个结果集里显示. UNION运算的一般语法: [表]查询1 UNION [ALL]查询2 UNION … 例:返回巴西所有供给商和客户的名字和城市 SELECT CompanyName,City FROM Suppliers WHERE Country = ‘Brazil’ UNION SELECT CompanyName,City FROM Customers WHERE Country = ‘Brazil’ 注: 缺省的情况下,UNION子句不返回重复的记录.如果想显示所有记录,可以加ALL选项 UNION运算要求查询具有相同数目的字段.但是,字段数据类型不必相同. 每一个查询参数中可以使用GROUP BY 子句 或 HAVING 子句进行分组.要想以指定的顺序来显示返回的数据,可以在最后一个查询的尾部使用OREER BY子句. 九. 交叉查询 交叉查询可以对数据进行总和,平均,计数或其他总和计算法的计算,这些数据通过两种信息进行分组:一个显示在表的左部,另一个显示在表的顶部. Microsoft Jet SQL 用TRANSFROM语句创建交叉表查询语法: TRANSFORM aggfunction SELECT 语句 GROUP BY 子句 PIVOT pivotfield[IN(value1 [,value2[,…]]) ] Aggfounction指SQL聚积函数, SELECT语句选择作为标题的的字段, GROUP BY 分组 说明: Pivotfield 在查询结果集中创建列标题时用的字段或表达式,用可选的IN子句限制它的取值. value代表创建列标题的固定值. 例:显示在1996年里每一季度每一位员工所接的定单的数目: TRANSFORM Count(OrderID) SELECT FirstName&’’&LastName AS FullName FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID WHERE DatePart(“yyyy”,OrderDate)= ‘1996’ GROUP BY FirstName&’’&LastName ORDER BY FirstName&’’&LastName POVOT DatePart(“q”,OrderDate)&’季度’ 十 .子查询 子查询可以理解为 套查询.子查询是一个SELECT语句. 1 表达式的值与子查询返回的单一值做比较 语法: 表达式 comparision [ANY|ALL|SOME](子查询) 说明: ANY 和SOME谓词是同义词,与比较运算符(=,,,=)一起使用.返回一个布尔值True或 False.ANY的意思是,表达式与子查询返回的一系列的值逐一比较,只要其中的一次比较产生True结果,ANY测试的返回 True值(既WHERE子句的结果),对应于该表达式的当前记录将进入主查询的结果中.ALL测试则要求表达式与子查询返回的一系列的值的比较都产生 True结果,才回返回True值. 例:主查询返回单价比任何一个折扣大于等于25%的产品的单价要高的所有产品 SELECT * FROM Products WHERE UnitPrice>ANY (SELECT UnitPrice FROM[Order Details] WHERE Discount>0.25) 2 检查表达式的值是否匹配子查询返回的一组值的某个值 语法: [NOT]IN(子查询) 例:返回库存价值大于等于1000的产品. SELECT ProductName FROM Products WHERE ProductID IN (SELECT PrdoctID FROM [Order DEtails] WHERE UnitPrice*Quantity>= 1000) 3检测子查询是否返回任何记录 语法: [NOT]EXISTS (子查询) 例:用EXISTS检索英国的客户 SELECT ComPanyName,ContactName FROM Orders WHERE EXISTS (SELECT * FROM Customers WHERE Country = ‘UK’ AND Customers.CustomerID= Orders.CustomerID)
MYSQL常用命令 1.导出整个数据库 mysqldump -u 用名 -p –default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql 3.导出一个数据库结构 mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql -d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table 4.导入数据库 A:常用source 命令 进入mysql数据库控制台, 如mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source wcnc_db.sql B:使用mysqldump命令 mysqldump -u username -p dbname < filename.sql C:使用mysql命令 mysql -u username -p -D dbname 2、退出MySQL:quit或exit 二、库操作 1、创建数据库 命令:create database 例如:建立一个名为xhkdb的数据库 mysql> create database xhkdb; 2、显示所有的数据库 命令:show databases (注意:最后有个s) mysql> show databases; 3、删除数据库 命令:drop database 例如:删除名为 xhkdb的数据库 mysql> drop database xhkdb; 4、连接数据库 命令:use 例如:如果xhkdb数据库存在,尝试存取它: mysql> use xhkdb; 屏幕提示:Database changed 5、查看当前使用的数据库 mysql> select database(); 6、当前数据库包含的表信息: mysql> show tables; (注意:最后有个s) 三、表操作,操作之前应连接某个数据库 1、建表 命令:create table ( [,.. ]); mysql> create table MyClass( > id int(4) not null primary key auto_increment, > name char(20) not null, > sex int(4) not null default ’′, > degree double(16,2)); 2、获取表结构 命令:desc 表名,或者show columns from 表名 mysql>DESCRIBE MyClass mysql> desc MyClass; mysql> show columns from MyClass; 3、删除表 命令:drop table 例如:删除表名为 MyClass 的表 mysql> drop table MyClass; 4、插入数据 命令:insert into [( [,.. ])] values ( 值 )[, ( 值n )] 例如,往表 MyClass中插入二条记录, 这二条记录表示:编号为的名为Tom的成绩为.45, 编号为 的名为Joan 的成绩为.99,编号为 的名为Wang 的成绩为.5. mysql>insert into MyClass values(1,’Tom’,96.45),(2,’Joan’,82.99), (2,’Wang’, 96.59); 5、查询表中的数据 1)、查询所有行 命令:select from where 例如:查看表 MyClass 中所有数据 mysql> select * from MyClass; 2)、查询前几行数据 例如:查看表 MyClass 中前行数据 mysql> select * from MyClass order by id limit 0,2; 或者: mysql> select * from MyClass limit 0,2; 6、删除表中数据 命令:delete from 表名 where 表达式 例如:删除表 MyClass中编号为 的记录 mysql> delete from MyClass where id=1; 7、修改表中数据:update 表名 set 字段=新值,…where 条件 mysql> update MyClass set name=’Mary’where id=1; 7、在表中增加字段: 命令:alter table 表名 add字段 类型 其他; 例如:在表MyClass中添加了一个字段passtest,类型为int(4),默认值为 mysql> alter table MyClass add passtest int(4) default ’′ 8、更改表名: 命令:rename table 原表名 to 新表名; 例如:在表MyClass名字更改为YouClass mysql> rename table MyClass to YouClass; 更新字段内容 update 表名 set 字段名 = 新内容 update 表名 set 字段名 = replace(字段名,’旧内容’,'新内容’) 文章前面加入个空格 update article set content=concat(‘  ’,content); 字段类型 1.INT[(M)] 型:正常大小整数类型 2.DOUBLE[(M,D)] [ZEROFILL] 型:正常大小(双精密)浮点数字类型 3.DATE 日期类型:支持的范围是-01-01到-12-31。MySQL以YYYY-MM-DD格式来显示DATE值,但是允许你使用字符串或数字把值赋给DATE列 4.CHAR(M) 型:定长字符串类型,当存储时,总是是用空格填满右边到指定的长度 5.BLOB TEXT类型,最大长度为(2^16-1)个字符。 6.VARCHAR型:变长字符串类型 5.导入数据库表   ()创建.sql文件   ()先产生一个库如auction.c:mysqlbin>mysqladmin -u root -p creat auction,会提示输入密码,然后成功创建。   ()导入auction.sql文件   c:mysqlbin>mysql -u root -p auction grant select,insert,delete,create,drop   on *.* (或test.*/user.*/..)   to 用户名@localhost   identified by ‘密码’;   如:新建一个用户帐号以便可以访问数据库,需要进行如下操作:   mysql> grant usage   -> ON test.*   -> TO testuser@localhost;   Query OK, 0 rows affected (0.15 sec)   此后就创建了一个新用户叫:testuser,这个用户只能从localhost连接到数据库并可以连接到test 数据库。下一步,我们必须指定testuser这个用户可以执行哪些操作:   mysql> GRANT select, insert, delete,update   -> ON test.*   -> TO testuser@localhost;   Query OK, 0 rows affected (0.00 sec)   此操作使testuser能够在每一个test数据库中的表执行SELECT,INSERT和DELETE以及UPDATE查询操作。现在我们结束操作并退出MySQL客户程序:   mysql> exit   Bye9! 1:使用SHOW语句找出在服务器上当前存在什么数据库: mysql> SHOW DATABASES; 2:2、创建一个数据库MYSQLDATA mysql> Create DATABASE MYSQLDATA; 3:选择你所创建的数据库 mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!) 4:查看现在的数据库中存在什么表 mysql> SHOW TABLES; 5:创建一个数据库表 mysql> Create TABLE MYTABLE (name VARCHAR(20), sex CHAR(1)); 6:显示表的结构: mysql> DESCRIBE MYTABLE; 7:往表中加入记录 mysql> insert into MYTABLE values (“hyq”,”M”); 8:用文本方式将数据装入数据库表中(例如D:/mysql.txt) mysql> LOAD DATA LOCAL INFILE “D:/mysql.txt”INTO TABLE MYTABLE; 9:导入.sql文件命令(例如D:/mysql.sql) mysql>use database; mysql>source d:/mysql.sql; 10:删除表 mysql>drop TABLE MYTABLE; 11:清空表 mysql>delete from MYTABLE; 12:更新表中数据 mysql>update MYTABLE set sex=”f”where name=’hyq’; 以下是无意中在络看到的使用MySql的管理心得, 在windows中MySql以服务形式存在,在使用前应确保此服务已经启动,未启动可用net start mysql命令启动。而Linux中启动时可用“/etc/rc.d/init.d/mysqld start”命令,注意启动者应具有管理员权限。 刚安装好的MySql包含一个含空密码的root帐户和一个匿名帐户,这是很大的安全隐患,对于一些重要的应用我们应将安全性尽可能提高,在这里应把匿名帐户删除、root帐户设置密码,可用如下命令进行: use mysql; delete from User where User=”"; update User set Password=PASSWORD(‘newpassword’) where User=’root’; 如果要对用户所用的登录终端进行限制,可以更新User表中相应用户的Host字段,在进行了以上更改后应重新启动数据库服务,此时登录时可用如下类似命令: mysql -uroot -p; mysql -uroot -pnewpassword; mysql mydb -uroot -p; mysql mydb -uroot -pnewpassword; 上面命令参数是常用参数的一部分,详细情况可参考文档。此处的mydb是要登录的数据库的名称。 在进行开发和实际应用中,用户不应该只用root用户进行连接数据库,虽然使用root用户进行测试时很方便,但会给系统带来重大安全隐患,也不利于管理技术的提高。我们给一个应用中使用的用户赋予最恰当的数据库权限。如一个只进行数据插入的用户不应赋予其删除数据的权限MySql的用户管理是通过User表来实现的,添加新用户常用的方法有两个,一是在User表插入相应的数据行,同时设置相应的权限;二是通过GRANT命令创建具有某种权限的用户。其中GRANT的常用用法如下: grant all on mydb.* to NewUserName@HostName identified by “password”; grant usage on *.* to NewUserName@HostName identified by “password”; grant select,insert,update on mydb.* to NewUserName@HostName identified by “password”; grant update,delete on mydb.TestTable to NewUserName@HostName identified by “password”; 若要给此用户赋予他在相应对象上的权限的管理能力,可在GRANT后面添加WITH GRANT OPTION选项。而对于用插入User表添加的用户,Password字段应用PASSWORD 函数进行更新加密,以防不轨之人窃看密码。对于那些已经不用的用户应给予清除,权限过界的用户应及时回收权限,回收权限可以通过更新User表相应字段,也可以使用REVOKE操作。 下面给出本人从其它资料(www.cn-java.com)获得的对常用权限的解释: 全局管理权限: FILE: 在MySQL服务器上读写文件。 PROCESS: 显示或杀死属于其它用户的服务线程。 RELOAD: 重载访问控制表,刷新日志等。 SHUTDOWN: 关闭MySQL服务。 数据库/数据表/数据列权限: Alter: 修改已存在的数据表(例如增加/删除列)和索引。 Create: 建立新的数据库或数据表。 Delete: 删除表的记录。 Drop: 删除数据表或数据库。 INDEX: 建立或删除索引。 Insert: 增加表的记录。 Select: 显示/搜索表的记录。 Update: 修改表中已存在的记录。 特别的权限: ALL: 允许做任何事(和root一样)。 USAGE: 只允许登录–其它什么也不允许做。 ——————— MYSQL常用命令 有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接MYSQL、修改密码、增加用户等方面来学习一些MYSQL的常用命令。   有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接MYSQL、修改密码、增加用户等方面来学习一些MYSQL的常用命令。    一、连接MYSQL    格式:mysql -h主机地址-u用户名-p用户密码     、例:连接到本机上的MYSQL   首先在打开DOS窗口,然后进入目录mysqlbin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>      、例:连接到远程主机上的MYSQL   假设远程主机的IP为:.110.110.110,用户名为root,密码为abcd123。则键入以下命令:      mysql -h110.110.110.110 -uroot -pabcd123      (注:u与root可以不用加空格,其它也一样)     、退出MYSQL命令:exit (回车)   二、修改密码     格式:mysqladmin -u用户名-p旧密码password 新密码    、例:给root加个密码ab12。首先在DOS下进入目录mysqlbin,然后键入以下命令     mysqladmin -uroot -password ab12      注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。     、例:再将root的密码改为djg345   mysqladmin -uroot -pab12 password djg345 MYSQL常用命令(下)   一、操作技巧   、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。也就是说你可以把一个完整的命令分成几行来打,完后用分号作结束标志就OK。   、你可以使用光标上下键调出以前的命令。但以前我用过的一个MYSQL旧版本不支持。我现在用的是mysql-3.23.27-beta-win。   二、显示命令   、显示数据库列表。   show databases;   刚开始时才两个数据库:mysql和test。mysql库很重要它里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。   、显示库中的数据表:   use mysql;//打开库,学过FOXBASE的一定不会陌生吧   show tables;   、显示数据表的结构:   describe 表名;   、建库:   create database 库名;   、建表:   use 库名;   create table 表名(字段设定列表);   、删库和删表:   drop database 库名;   drop table 表名;   、将表中记录清空:   delete from 表名;   、显示表中的记录:   select * from 表名; 三、一个建库和建表以及插入数据的实例   drop database if exists school; //如果存在SCHOOL则删除   create database school; //建立库SCHOOL   use school; //打开库SCHOOL   create table teacher //建立表TEACHER   (   id int(3) auto_increment not null primary key,   name char(10) not null,   address varchar(50) default ‘深圳’,   year date   ); //建表结束   //以下为插入字段   insert into teacher values(”,’glchengang’,'深圳一中’,’-10-10′);   insert into teacher values(”,’jack’,'深圳一中’,’-12-23′);   注:在建表中()将ID设为长度为的数字字段:int(3)并让它每个记录自动加一:auto_increment并不能为空:not null而且让他成为主字段primary key   ()将NAME设为长度为的字符字段   ()将ADDRESS设为长度的字符字段,而且缺省值为深圳。varchar和char有什么区别呢,只有等以后的文章再说了。   ()将YEAR设为日期字段。   如果你在mysql提示符键入上面的命令也可以,但不方便调试。你可以将以上命令原样写入一个文本文件中假设为school.sql,然后复制到c:\下,并在DOS状态进入目录\mysql\bin,然后键入以下命令:   mysql -uroot -p密码school.bbb   注释:将数据库school备份到school.bbb文件,school.bbb是一个文本文件,文件名任取,打开看看你会有新发现。 一.SELECT语句的完整语法为: SELECT[ALL|DISTINCT|DISTINCTROW|TOP] {*|talbe.*|[table.]field1[AS alias1][,[table.]field2[AS alias2][,…]]} FROM tableexpression[,…][IN externaldatabase] [WHERE…] [GROUP BY…] [HAVING…] [ORDER BY…] [WITH OWNERACCESS OPTION] 说明: 用中括号([])括起来的部分表示是可选的,用大括号({})括起来的部分是表示必须从中选择其中的一个。 1 FROM子句 FROM 子句指定了SELECT语句中字段的来源。FROM子句后面是包含一个或多个的表达式(由逗号分开),其中的表达式可为单一表名称、已保存的查询或由INNER JOIN、LEFT JOIN 或RIGHT JOIN 得到的复合结果。如果表或查询存储在部数据库,在IN 子句之后指明其完整路径。 例:下列SQL语句返回所有有定单的客户: SELECT OrderID,Customer.customerID FROM Orders Customers WHERE Orders.CustomerID=Customers.CustomeersID 2 ALL、DISTINCT、DISTINCTROW、TOP谓词 (1) ALL 返回满足SQL语句条件的所有记录。如果没有指明这个谓词,默认为ALL。 例:SELECT ALL FirstName,LastName FROM Employees (2) DISTINCT 如果有多个记录的选择字段的数据相同,只返回一个。 (3) DISTINCTROW 如果有重复的记录,只返回一个 (4) TOP显示查询头尾若干记录。也可返回记录的百分比,这是要用TOP N PERCENT子句(其中N 表示百分比) 例:返回%定货额最大的定单 SELECT TOP 5 PERCENT* FROM [ Order Details] ORDER BY UnitPrice*Quantity*(1-Discount) DESC 3 用AS 子句为字段取别名 如果想为返回的列取一个新的标题,或者,经过对字段的计算或总结之后,产生了一个新的值,希望把它放到一个新的列里显示,则用AS保留。 例:返回FirstName字段取别名为NickName SELECT FirstName AS NickName ,LastName ,City FROM Employees 例:返回新的一列显示库存价值 SELECT ProductName ,UnitPrice ,UnitsInStock ,UnitPrice*UnitsInStock AS valueInStock FROM Products 二.WHERE 子句指定查询条件 1 比较运算符 比较运算符含义 = 等于 > 大于 = 大于等于 <= 小于等于 不等于 !> 不大于 !#1/1/96# AND OrderDate#96-1-1# 也可以表示为: WHERE OrderDate>Datevalue(‘/1/96’) 使用NOT 表达式求反。 例:查看年月日以后的定单 WHERE Not OrderDateQuantity 另一种方法是用Microsof JET SQL 独有的JNNER JOIN 语法: FROM table1 INNER JOIN table2 ON table1.field1 comparision table2.field2 其中comparision 就是前面WHERE子句用到的比较运算符。 SELECT FirstName,lastName,OrderID,CustomerID,OrderDate FROM Employees INNER JOIN Orders ON Employees.EmployeeID=Orders.EmployeeID 注意: INNER JOIN不能连接Memo OLE Object Single Double 数据类型字段。 在一个JOIN语句中连接多个ON子句 语法: SELECT fields FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field1 AND ON table1.field2 compopr table2.field2 OR ON table1.field3 compopr table2.field3 也可以 SELECT fields FROM table1 INNER JOIN (table2 INNER JOIN [( ]table3 [INNER JOER] [( ]tablex[INNER JOIN] ON table1.field1 compopr table2.field1 ON table1.field2 compopr table2.field2 ON table1.field3 compopr table2.field3 部连接返回更多记录,在结果中保留不匹配的记录,不管存不存在满足条件的记录都要返回另一侧的所有记录。 FROM table [LEFT|RIGHT]JOIN table2 ON table1.field1comparision table.field2 用左连接来建立部连接,在表达式的左边的表会显示其所有的数据 例:不管有没有定货量,返回所有商品 SELECT ProductName ,OrderID FROM Products LEFT JOIN Orders ON Products.PrductsID=Orders.ProductID 右连接与左连接的差别在于:不管左侧表里有没有匹配的记录,它都从左侧表中返回所有记录。 例:如果想了解客户的信息,并统计各个地区的客户分布,这时可以用一个右连接,即使某个地区没有客户,也要返回客户信息。 空值不会相互匹配,可以通过连接才能测试被连接的某个表的字段是否有空值。 SELECT * FROM talbe1 LEFT JOIN table2 ON table1.a=table2.c 1 连接查询中使用Iif函数实现以值显示空值 Iif表达式:Iif(IsNull(Amount,0,Amout) 例:无论定货大于或小于¥,都要返回一个标志。 Iif([Amount]>50,?Big order?,?Small order?) 五. 分组和总结查询结果 在SQL的语法里,GROUP BY和HAVING子句用来对数据进行汇总。GROUP BY子句指明了按照哪几个字段来分组,而将记录分组后,用HAVING子句过滤这些记录。 GROUP BY 子句的语法 SELECT fidldlist FROM table WHERE criteria [GROUP BY groupfieldlist [HAVING groupcriteria]] 注:Microsoft Jet数据库Jet 不能对备注或OLE对象字段分组。 GROUP BY字段中的Null值以备分组但是不能被省略。 在任何SQL合计函数中不计算Null值。 GROUP BY子句后最多可以带有十个字段,排序优先级按从左到右的顺序排列。 例:在‘WA’地区的雇员表中按头衔分组后,找出具有同等头衔的雇员数目大于人的所有头衔。 SELECT Title ,Count(Title) as Total FROM Employees WHERE Region = ‘WA’ GROUP BY Title HAVING Count(Title)>1 JET SQL 中的聚积函数 聚集函数意义 SUM ( ) 求和 AVG ( ) 平均值 COUNT ( ) 表达式中记录的数目 COUNT (* ) 计算记录的数目 MAX 最大值 MIN 最小值 VAR 方差 STDEV 标准误差 FIRST 第一个值 LAST 最后一个值 六. 用Parameters声明创建参数查询 Parameters声明的语法: PARAMETERS name datatype[,name datatype[, …]] 其中name 是参数的标志符,可以通过标志符引用参数. Datatype说明参数的数据类型. 使用时要把PARAMETERS 声明置于任何其他语句之前. 例: PARAMETERS[Low price] Currency,[Beginning date]datatime SELECT OrderID ,OrderAmount FROM Orders WHERE OrderAMount>[low price] AND OrderDate>=[Beginning date] 七. 功能查询 所谓功能查询,实际上是一种操作查询,它可以对数据库进行快速高效的操作.它以选择查询为目的,挑选出符合条件的数据,再对数据进行批处理.功能查询包括更新查询,删除查询,添加查询,和生成表查询. 1 更新查询 UPDATE子句可以同时更改一个或多个表中的数据.它也可以同时更改多个字段的值. 更新查询语法: UPDATE 表名 SET 新值 WHERE 准则 例:英国客户的定货量增加%,货运量增加% UPDATE OEDERS SET OrderAmount = OrderAmount *1.1 Freight = Freight*1.03 WHERE ShipCountry = ‘UK’ 2 删除查询 DELETE子句可以使用户删除大量的过时的或冗于的数据. 注:删除查询的对象是整个记录. DELETE子句的语法: DELETE [表名.*] FROM 来源表 WHERE 准则 例: 要删除所有年前的定单 DELETE * FROM Orders WHERE OrderData<#94-1-1# 3 追加查询 INSERT子句可以将一个或一组记录追加到一个或多个表的尾部. INTO 子句指定接受新记录的表 valueS 关键字指定新记录所包含的数据值. INSERT 子句的语法: INSETR INTO 目的表或查询(字段,字段,…) valueS(数值,数值,…) 例:增加一个客户 INSERT INTO Employees(FirstName,LastName,title) valueS(‘Harry’,’Washington’,’Trainee’) 4 生成表查询 可以一次性地把所有满足条件的记录拷贝到一张新表中.通常制作记录的备份或副本或作为报表的基础. SELECT INTO子句用来创建生成表查询语法: SELECT 字段,字段,… INTO 新表[IN 部数据库] FROM 来源数据库 WHERE 准则 例:为定单制作一个存档备份 SELECT * INTO OrdersArchive FROM Orders 八. 联合查询 UNION运算可以把多个查询的结果合并到一个结果集里显示. UNION运算的一般语法: [表]查询UNION [ALL]查询UNION … 例:返回巴西所有供给商和客户的名字和城市 SELECT CompanyName,City FROM Suppliers WHERE Country = ‘Brazil’ UNION SELECT CompanyName,City FROM Customers WHERE Country = ‘Brazil’ 注: 缺省的情况下,UNION子句不返回重复的记录.如果想显示所有记录,可以加ALL选项 UNION运算要求查询具有相同数目的字段.但是,字段数据类型不必相同. 每一个查询参数中可以使用GROUP BY 子句或HAVING 子句进行分组.要想以指定的顺序来显示返回的数据,可以在最后一个查询的尾部使用OREER BY子句. 九. 交叉查询 交叉查询可以对数据进行总和,平均,计数或其他总和计算法的计算,这些数据通过两种信息进行分组:一个显示在表的左部,另一个显示在表的顶部. Microsoft Jet SQL 用TRANSFROM语句创建交叉表查询语法: TRANSFORM aggfunction SELECT 语句 GROUP BY 子句 PIVOT pivotfield[IN(value1 [,value2[,…]]) ] Aggfounction指SQL聚积函数, SELECT语句选择作为标题的的字段, GROUP BY 分组 说明: Pivotfield 在查询结果集中创建列标题时用的字段或表达式,用可选的IN子句限制它的取值. value代表创建列标题的固定值. 例:显示在年里每一季度每一位员工所接的定单的数目: TRANSFORM Count(OrderID) SELECT FirstName&’’&LastName; AS FullName FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID WHERE DatePart(“yyyy”,OrderDate)= ‘’ GROUP BY FirstName&’’&LastName; ORDER BY FirstName&’’&LastName; POVOT DatePart(“q”,OrderDate)&’季度’ 十.子查询 子查询可以理解为套查询.子查询是一个SELECT语句. 1 表达式的值与子查询返回的单一值做比较 语法: 表达式comparision [ANY|ALL|SOME](子查询) 说明: ANY 和SOME谓词是同义词,与比较运算符(=,,,=)一起使用.返回一个布尔值True或False.ANY的意思是,表达式与子查询返回的一系列的值逐一比较,只要其中的一次比较产生True结果,ANY测试的返回True值(既WHERE子句的结果),对应于该表达式的当前记录将进入主查询的结果中.ALL测试则要求表达式与子查询返回的一系列的值的比较都产生True结果,才回返回True值. 例:主查询返回单价比任何一个折扣大于等于%的产品的单价要高的所有产品 SELECT * FROM Products WHERE UnitPrice>ANY (SELECT UnitPrice FROM[Order Details] WHERE Discount>0.25) 2 检查表达式的值是否匹配子查询返回的一组值的某个值 语法: [NOT]IN(子查询) 例:返回库存价值大于等于的产品. SELECT ProductName FROM Products WHERE ProductID IN (SELECT PrdoctID FROM [Order DEtails] WHERE UnitPrice*Quantity>= 1000) 3检测子查询是否返回任何记录 语法: [NOT]EXISTS (子查询) 例:用EXISTS检索英国的客户 SELECT ComPanyName,ContactName FROM Orders WHERE EXISTS (SELECT * FROM Customers WHERE Country = ‘UK’AND Customers.CustomerID= Orders.CustomerID)
简单配置: 1、设置phpmyadmin 在WampServer安装完成后,通过http://localhost/打开后可以看到WampServer自带的一个简单的页面,里面有phpinfo、phpmyadmin和sqlitemanager三个工具。 打开phpmyadmin会在下方看到提示,root用户没有设置密码,我们先为root帐户设置密码。点击phpmyadmin页面中部的“权限”,可以看到“用户一览”,这时候应该只有一行用户信息,即root localhost这一行,点击这一行最右侧的编辑权限图标,在新页面找到“更改密码”,为root用户设置密码,并点击“执行”。 然后刷新页面,会看到错误提示,这是因为帐户已经设置密码,到WampServer程序安装目录,在apps目录找到phpmyadmin的目录,打开phpmyadmin目录里面的config.inc.php文件,找到下面这一行: $cfg['Servers'][$i]['password'] = ''; 在等号右面的单引号里面输入刚才设置的密码,重新打开phpmyadmin的页面并刷新,这时候phpmyadmin就可以正常访问了。 好了,我已经用WampServer简单的架设起一个Apache + PHP + MySQL的服务器了。 ----------------------------------------------------------- 2、允许访问: wamp 默认是禁止访问APACHE的,左键点击右下的wamp图标Apache - httpd.conf ,搜索关键字 "deny from ",会发现一处 "deny from"将其下的一行"Allow from 127.0.0.1" 之前加一个 #号,表示注释掉,新插入一行,手动输入Allow from all 。保存,重新启动下apache 服务就可以允许访问了。 3、apache, mysql 服务的开机自动运行 Windows - 开始? - 设置 - 控制面板 - 管理工具 - 服务,找到 wampmysqld, wampapache, 将 "启动类型" 由"手动" 改为"自动" 即可。 4、开启支持rewrite module #LoadModule rewrite_module modules/mod_rewrite.so 去前面掉#,修改为 LoadModule rewrite_module modules/mod_rewrite.so Options FollowSymLinks AllowOverride None # 修改为AllowOverride All # Order deny,allow Deny from all Satisfy all # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # 修改为AllowOverride All # # # Controls who can get stuff from this server. # Order allow,deny Allow
资源名称:___开单大师学习版4.0.4__ 资源分类:___PHP源码→办公管理___ 授权方式:___免费开源___ 界面语言:___简体中文___ 文件大小:___30.5MB(30509KB))___ 更新时间:___2021年12月8日___ 资源类型:___国产软件___ 平台环境:___(软件)win all/___(源码)php+mysql___ 作者主页:__http://www.kaidandashi.com/__ 演示地址:__http://demo.kaidandashi.com/__ 官方下载链接: 百度盘:https://pan.baidu.com/s/1agEzjmJn7_TbDMAr-WFw7w 提取码:kdds 本地下载1:http://www.kaidandashi.com/fczjerp/kddsxxb.zip 本地下载2:http://www.kaidandashi.com/fczjerp/开单大师学习版.zip 详细介绍: 软件简介: 首家100%开源可定制的房产中介ERP管理系统,手机、电脑、微信、Pad同步使用,内高级结合,四合一、一站同步、提高工作效率、安全可靠、操作简单。 详细介绍: 开源可定制房产中介 ERP 解决方案: 开单大师是全国首家提供房产管理系统和房屋管理系统源代码的服务商,系统拥有功能完善的房源客源管理,同时提供完备的办公、财务、决策分析方案,内一体全面打通。 开单大师100%开放的源代码,您可以自由掌控,定制开发属于您的专属功能。无店面和用户数限制,一次买断,永久使用。安全掌控您的软件服务器,隐私数据自己掌控。开单大师,为每家中介提供真正属于自己的房产中介管理系统。 整合微信平台:借力微信,快速分享。 开单大师内管理ERP:功能全面,适合不同运营需求。 房客源管理:内同步,一站打通。 一体化同步设计思想:开单大师房产管理系统平台上搭建全部业务模块,不论是标准产品还是个性研发都遵循规范要求,包括取数规则,交互方式,界面样式和美工风格都全部有统一化标准。 产品特色: 技术方案成熟稳定,支持各类房产中介业务场景,开单大师房产管理系统平台集成内平台应用系统,帮您一站式快速搭建专属的房产中介平台。 房源管理:开单大师支持络多门店,多人联系统工作。中介站无缝集成和微站无缝集成,提升中介门店服务能力,更高效。 权限和设置:各种角色和权限设置,不限门店,员工数量。可灵活设置每一位经纪人的权限,认证机器,可限制经纪人只能在门店内电脑登录。 全新智能激励辅助运营:根据个人业务动作所占成交比例预知业绩金额,发挥经纪人主观能动性,加速成交进程! 移动端应用:特色移动端应用,方便快捷查询管理。实时数据更新,事件准时提示。让您随心掌握,想改就改。 微信分享:经纪人可对自己的订单进行评价和分享,也可在微商城、圈子等多频道进行分享。 强大的财务报表分析中心:大数据智能分析业绩数据,了解业绩走势。门店损益状况一目了然,让门店运营状况尽在您的眼中! 在线客服:经纪人与客户随时沟通,轻松解决客户疑问,不在受疑难杂症的烦恼。 三大日志辅助运营:三大日志相辅相成,让一切尽在掌握,为您的数据安全提供优质的保护。 定制开发:开单大师为不同的要求,提供最适合的定制化解决方案。 除了以上特性,开单大师还用心为您准备了更多的贴心功能等待您的发现…… 常见问题: 1、开源可定制是什么意思 软件代码开放,懂技术的可以自己调整或者新增功能,如果自己对技术不太懂可以联系我们公司给您定制您需要的功能 2、开单大师只能用于房产吗 目前开单大师只针对写字楼、商铺、二手房、新楼盘、新房分销等做了不同的版本,包括运营版也是针对房产中介开发的,不过如果您需要其他行业的软件我们也可以给您定制开发 3、开单大师如何安装 解压压缩包后有一个名为开单大师4.0.4学习版的文件夹,打开文件夹中的4.0.4使用说明,里面有详细的安装步骤 更新日志: 1、优化了房源开盘日志列表查询。 2、优化了客源列表的查询功能 3、优化了用户通讯录的搜索功能 4、新增了选项配置中的房屋类型选项

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值