MariaDB & MySQL 的安装配置

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

MariaDB

https://downloads.mariadb.org/服务器

MySQL

http://dev.mysql.com/downloads/mysql/less

下拉菜单【Select Platform:】
MS windows
ubuntu linux
debian linux
FreeBSD
...
SourceCode等等socket

我是下载的这个Windows 64bits

下面是一些文档相关
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


安装

安装的话,默认有配置文件,

windows 是my.ini (安装目录下my-default.ini 改过来)

# 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下如何执行sql脚本

首要步骤(通常可省略):
开启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 【检索数据】


linux 下的配置文件 my.cnf (路径是/etc/mysql/my.cnf)

server-system-variables 介绍

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';

附表:在MySQL中的操做权限

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.
相关文章
相关标签/搜索