Mysql建立及刪除用戶命令html
MariaDB安裝方法圖文詳解mysql
Tips: MariaDB 新版本沒有ini 配置文件了
win10運行MariaDBlinux
The default root password is blank (i.e. empty string) not root. So you can just login as:sql
mysql -u root
You should obviously change your root password after installation數據庫
mysqladmin -u root password [newpassword]
In most cases you should also set up individual user accounts before working extensively with the DB as well.ubuntu
下載windows
https://downloads.mariadb.org/服務器
http://dev.mysql.com/downloads/mysql/less
下拉菜單【Select Platform:】
MS windows
ubuntu linux
debian linux
FreeBSD
...
SourceCode等等socket
下面是一些文檔相關
http://www.mysql.com/downloads/
http://dev.mysql.com/doc/refman/5.7/en/installing.html
2.1 General Installation Guidance
2.2 Installing MySQL on Unix/Linux Using Generic Binaries
2.3 Installing MySQL on Microsoft Windows
2.4 Installing MySQL on OS X
2.5 Installing MySQL on Linux
2.6 Installing MySQL Using Unbreakable Linux Network (ULN)
2.7 Installing MySQL on Solaris and OpenSolaris
2.8 Installing MySQL on FreeBSD
2.9 Installing MySQL from Source
2.10 Postinstallation Setup and Testing
2.11 Upgrading or Downgrading MySQL
2.12 Environment Variables
2.13 Perl Installation Notes
安裝
安裝的話,默認有配置文件,
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # 設置mysql的安裝目錄 basedir = D:\Program Files\mysql-5.7.10-winx64 # 設置mysql數據庫的數據的存放目錄 datadir = D:\Program Files\mysql-5.7.10-winx64\data #綁定IPv4和3306端口 # bind-address = 0.0.0.0 port = 3306 #這個是默認數字,別用字符,字符串, 主從機器,或者分佈式機器,就用這個來區分機器 server_id = 10 #服務端字符類型,建議utf8 character_set_server=utf8 # 容許最大鏈接數 max_connections=200 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [WinMySQLAdmin] Server=D:\Program Files\mysql-5.7.10-winx64\bin\mysqld.exe #下面是客戶端,默認不用添加 #[client] #port=3306 #客戶端字符類型,與服務端一致就行,建議utf8 #default-character-set=utf8
MARIADB = yourPath\\bin
Path中添加 ;%MARIADB%;
打開CMD,輸入mysql -u root -p
以root用戶登陸,而後設置權限。
mysql -p 65534 -u root -p`指定用哪一個端口,開啓mysql服務。
=====================
首要步驟(通常可省略):
開啓mysql服務(默認是開機時就自動運行了):
控制面板-->管理工具-->服務,在裏面找到名稱爲mysql的項,雙擊就可看它的服務狀態是啓動仍是中止,把它設爲啓動
鏈接mysql:
在命令行下輸入 mysql -h localhost -u root -p回車,而後輸入密碼便可;或直接運行mysql自帶的鏈接工具,而後輸入密碼便可.
1.編寫sql腳本,假設內容以下:
create database dearabao;
use dearabao;
create table niuzi (name varchar(20));
保存腳本文件,假設我把它保存在F盤的hello world目錄下,因而該文件的路徑爲:F:\hello world\niuzi.sql
2.執行sql腳本,能夠有2種方法:
第一種方法:
在命令行下(未鏈接數據庫),輸入 mysql -h localhost -u root -p123456 < F:\hello world\niuzi.sql (注意路徑不用加引號的!!) 回車便可.
第二種方法:
在命令行下(已鏈接數據庫,此時的提示符爲 mysql> ),輸入 source F:\hello world\niuzi.sql (注意路徑不用加引號的) 或者 . F:\hello world\niuzi.sql (注意路徑不用加引號的) 回車便可
我mysql沒有設置密碼。直接打開CMD,輸入mysql,進入mysql命令行狀態。輸入source E:\123.sql
====================
CREATE USER 'myusername'@'%' IDENTIFIED BY 'mypassword';
GRANT ALL ON *.* TO 'myusername'@'%';
參考MariaDB(MySQL)的經常使用命令1 【檢索數據】
scott@ubuntu:/etc/mysql$ cat my.cnf # # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking #服務端字符類型,建議utf8 character_set_server=utf8 # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. # bind-address = 127.0.0.1 # # * Fine Tuning # key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log # # Here you can see queries with especially long duration #log_slow_queries = /var/log/mysql/mysql-slow.log #long_query_time = 2 #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/
命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';
說明:username - 你將建立的用戶名, host - 指定該用戶在哪一個主機上能夠登錄,若是是本地用戶可用localhost, 若是想讓該用戶能夠從任意遠程主機登錄,可使用通配符%. password - 該用戶的登錄密碼,密碼能夠爲空,若是爲空則該用戶能夠不須要密碼登錄服務器.
例子: CREATE USER 'username'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'username'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'username'@'%' IDENTIFIED BY '123456';
CREATE USER 'username'@'%' IDENTIFIED BY '';
CREATE USER 'username'@'%';
命令:GRANT privileges ON databasename.tablename TO 'username'@'host'
說明: privileges - 用戶的操做權限,如SELECT , INSERT , UPDATE 等(詳細列表見該文最後面).若是要授予所的權限則使用ALL.;databasename - 數據庫名,tablename-表名,若是要授予該用戶對全部數據庫和表的相應操做權限則可用表示, 如.*.
例子: GRANT SELECT, INSERT ON test.user TO 'username'@'%';
GRANT ALL ON . TO 'username'@'%';
注意:用以上命令受權的用戶不能給其它用戶受權,若是想讓該用戶能夠受權,用如下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
命令:SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');若是是當前登錄用戶用SET PASSWORD = PASSWORD("newpassword");
例子: SET PASSWORD FOR 'username'@'%' = PASSWORD("123456");
命令: REVOKE privilege ON databasename.tablename FROM 'username'@'host';
說明: privilege, databasename, tablename - 同受權部分.
例子: REVOKE SELECT ON . FROM 'username'@'%';
注意: 假如你在給用戶'username'@'%'受權的時候是這樣的(或相似的):GRANT SELECT ON test.user TO 'username'@'%', 則在使用REVOKE SELECT ON . FROM 'username'@'%';命令並不能撤銷該用戶對test數據庫中user表的SELECT 操做.相反,若是受權使用的是GRANT SELECT ON . TO 'username'@'%';則REVOKE SELECT ON test.user FROM 'username'@'%';命令也不能撤銷該用戶對test數據庫中user表的Select 權限.
具體信息能夠用命令SHOW GRANTS FOR 'username'@'%'; 查看.
五.刪除用戶
命令: DROP USER 'username'@'host';
ALTER Allows use of ALTER TABLE. ALTER ROUTINE Alters or drops stored routines. CREATE Allows use of CREATE TABLE. CREATE ROUTINE Creates stored routines. CREATE TEMPORARY TABLE Allows use of CREATE TEMPORARY TABLE. CREATE USER Allows use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES. CREATE VIEW Allows use of CREATE VIEW. DELETE Allows use of DELETE. DROP Allows use of DROP TABLE. EXECUTE Allows the user to run stored routines. FILE Allows use of SELECT... INTO OUTFILE and LOAD DATA INFILE. INDEX Allows use of CREATE INDEX and DROP INDEX. INSERT Allows use of INSERT. LOCK TABLES Allows use of LOCK TABLES on tables for which the user also has SELECT privileges. PROCESS Allows use of SHOW FULL PROCESSLIST. RELOAD Allows use of FLUSH. REPLICATION Allows the user to ask where slave or master CLIENT servers are. REPLICATION SLAVE Needed for replication slaves. SELECT Allows use of SELECT. SHOW DATABASES Allows use of SHOW DATABASES. SHOW VIEW Allows use of SHOW CREATE VIEW. SHUTDOWN Allows use of mysqladmin shutdown. SUPER Allows use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL SQL statements. Allows mysqladmin debug command. Allows one extra connection to be made if maximum connections are reached. UPDATE Allows use of UPDATE. USAGE Allows connection without any specific privileges.