一.1.1 MYSQL

一.1.1.1 基础特性

1)性能卓越,服务稳定,很少出现异常宕机;

2)开放源代码且无版权制约,自主性强,使用成本低;

3)历史悠久,社区及用户非常活跃,遇到问题,可快速获得帮助;

4)软件体积小,安装使用简单,易于维护,安装及维护成本低;

5)支持多种操作系统,提供多种API接口,支持多种开发语言,对PHP语言语言无缝支持;

6)品牌口碑效应。

一.1.1.2 基础说明

:数据库重新初始化要切记先删除data对应目录的数据。

企业环境创建数据库:

a.根据开发的程序确定字符集(建议UTF8);

b.编译时指定字符集,例如:

-DDEFAULT_CHATSET=utf8 \

-DDEFAULT_CHLLATION=utf8_general_ci \

c.当需要的字符集不同于默认字符集时,指定字符集创建数据库即可。

企业环境数据库授权状态:

a.博客、CMS等产品的数据库授权:

对于web连接用户尽量采用最小化原则,较多开源软件都是web界面安装,需要SELECTINSERTUPDATEDELETECREATEDROP(较危险)权限;

> grant select,insert,update,delete,create,drop on blog.* to ‘blog’@’10.0.0.%’ identified by ‘000000’;

b.生成数据库表后,要收回CREATEDROP权限;

> REVOKE CREATE on blog.* FROM ‘blog’@’10.0.0.%’;

> REVOKE DROP on blog.* FROM ‘blog’@’10.0.0.%’;

c.生产环境针对主库(写为主读为辅)用户的授权;

主库

> GRANT SELECT,INSERT,UPDATE,DELETE ON ‘blog’.* TO ‘blog’@’10.0.0.%’ identified by ‘000000’;

从库

> GRANT SELECT ON ‘blog’.* TO ‘blog’@’10.0.0.%’ identified by ‘000000’;

mysql记录UUID的文件

[root@M-mysql /r2/mysqldata]# cat auto.cnf

[auto]

server-uuid=fda28692-9e31-11e7-bf34-000c2907c998

数据库操作记录文件

/root/.mysql_history

mysql参数说明

-V  --version  查看版本;-e  实现非交换式对话;-U 当发出没有WHERELIMIT关键字的UPDATEDELETE时,mysql程序将拒绝执行;

防止数据库误操作

# echo “alias mysql=’mysql -U’” >>/etc/profile

# source /etc/profile

不重启数据库调整参数

> set global key_buffer_size=10*1024*1024;

# 此操作为全局参数设置,设置完立即生效,重启MySQL后失效,所以若想不重启修改数据库参数并永久生效,可用此操作设置完后再修改对应的配置文件里参数。

登陆数据库后执行系统命令

> system ls -la  /tmp

ALL PRIVILEGES包括如下权限

 SELECT, INSERT,UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE

一.1.1.3 配置说明

公司集群环境配置文件

  1 # Example MySQL config file for very large systems.
  2 #
  3 # This is for a large system with memory of 1G-2G where the system runs mainly
  4 # MySQL.
  5 #
  6 # MySQL programs look for option files in a set of
  7 # locations which depend on the deployment platform.
  8 # You can copy this option file to one of those
  9 # locations. For information about these locations, see:
 10 # http://dev.mysql.com/doc/mysql/en/option-files.html
 11 #
 12 # In this file, you can use all long options that a program supports.
 13 # If you want to know which options a program supports, run the program
 14 # with the "--help" option.
 15 
 16 # The following options will be passed to all MySQL clients
 17 [client]
 18 # password        = yourpassword
 19 port        = 3306
 20 socket        = /usr/local/mysql/data/mysql.sock
 21 # default-character-set=utf8
 22 
 23 # Here follows entries for some specific programs
 24 
 25 # The MySQL server
 26 [mysqld]
 27 # password        = yourpassword
 28 server-id         =1                          # 主机标示,整数                
 29 read-only         =0                          # 主机,读写都可以                 
 30 #binlog-do-db     =mysql                      # 需要备份数据,多个写多行
 31 #replicate-wild-ignor2-table=mysql.%    
 32 #binlog-ignore-db  =mysql                     # 不需要备份的数据库,多个写多行
 33 port        = 3306
 34 socket        = /usr/local/mysql/data/mysql.sock
 35 max_connections=10000
 36 max_connect_errors=10000
 37 #init-connect='SET NAMES utf8;insert into accesslog.accesslog values(null,connection_id(),now(),substring(user(),1,locate('@',user())-1),substring(user(),locate('@',user())+1,length(user())));'
 38 init-connect='SET NAMES utf8'
 39 interactive_timeout=31536000
 40 #default-character-set=utf8
 41 datadir=/r2/mysqldata
 42 basedir=/usr/local/mysql
 43 log-error=/r2/mysqldata/mysql-error.log
 44 pid-file=/r2/mysqldata/mysql.pid
 45 #bind-address=127.0.0.1
 46 user=mysql
 47 #skip-locking
 48 key_buffer_size = 384M
 49 max_allowed_packet = 64M
 50 table_open_cache = 512
 51 sort_buffer_size = 2M
 52 read_buffer_size = 2M
 53 read_rnd_buffer_size = 8M
 54 myisam_sort_buffer_size = 64M
 55 thread_cache_size = 8
 56 query_cache_size = 32M
 57 # Try number of CPU's*2 for thread_concurrency
 58 #thread_concurrency = 8
 59 
 60 log-slave-updates #这个参数一定要加上,否则不会给更新的记录些到二进制文件里
 61 #slave-skip-errors #是跳过错误,继续执行复制操作
 62 
 63 expire_logs_days = 18 
 64 
 65 # Don't listen on a TCP/IP port at all. This can be a security enhancement,
 66 # if all processes that need to connect to mysqld run on the same host.
 67 # All interaction with mysqld must be made via Unix sockets or named pipes.
 68 # Note that using this option without enabling named pipes on Windows
 69 # (via the "enable-named-pipe" option) will render mysqld useless!
 70 # 
 71 #skip-networking
 72 
 73 # Replication Master Server (default)
 74 # binary logging is required for replication
 75 log-bin=mysql-bin
 76 
 77 # required unique id between 1 and 2^32 - 1
 78 # defaults to 1 if master-host is not set
 79 # but will not function as a master if omitted
 80 
 81 # Replication Slave (comment out master section to use this)
 82 #
 83 # To configure this host as a replication slave, you can choose between
 84 # two methods :
 85 #
 86 # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
 87 #    the syntax is:
 88 #
 89 #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
 90 #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
 91 #
 92 #    where you replace <host>, <user>, <password> by quoted strings and
 93 #    <port> by the master's port number (3306 by default).
 94 #
 95 #    Example:
 96 #
 97 #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
 98 #    MASTER_USER='joe', MASTER_PASSWORD='secret';
 99 #
100 # OR
101 #
102 # 2) Set the variables below. However, in case you choose this method, then
103 #    start replication for the first time (even unsuccessfully, for example
104 #    if you mistyped the password in master-password and the slave fails to
105 #    connect), the slave will create a master.info file, and any later
106 #    change in this file to the variables' values below will be ignored and
107 #    overridden by the content of the master.info file, unless you shutdown
108 #    the slave server, delete master.info and restart the slaver server.
109 #    For that reason, you may want to leave the lines below untouched
110 #    (commented) and instead use CHANGE MASTER TO (see above)
111 #
112 # required unique id between 2 and 2^32 - 1
113 # (and different from the master)
114 # defaults to 2 if master-host is set
115 # but will not function as a slave if omitted
116 #server-id       = 2
117 #
118 # The replication master for this slave - required
119 #master-host     =   <hostname>
120 #
121 # The username the slave will use for authentication when connecting
122 # to the master - required
123 #master-user     =   <username>
124 #
125 # The password the slave will authenticate with when connecting to
126 # the master - required
127 #master-password =   <password>
128 #
129 # The port the master is listening on.
130 # optional - defaults to 3306
131 #master-port     =  <port>
132 #
133 # binary logging - not required for slaves, but recommended
134 #log-bin=mysql-bin
135 #
136 # binary logging format - mixed recommended 
137 binlog_format=mixed
138 
139 # Uncomment the following if you are using InnoDB tables
140 #innodb_data_home_dir = /var/lib/mysql
141 #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
142 #innodb_log_group_home_dir = /var/lib/mysql
143 # You can set .._buffer_pool_size up to 50 - 80 %
144 # of RAM but beware of setting memory usage too high
145 innodb_buffer_pool_size = 30720M
146 sync_binlog=0
147 query_cache_type= ON
148 query_cache_size= 128M
149 gtid_mode=ON                                                                                                                                                                                         
150 enforce_gtid_consistency=ON
151 slave_parallel_type=LOGICAL_CLOCK
152 slave_parallel_workers=16                                                           
153 master_info_repository=TABLE
154 relay_log_info_repository=TABLE
155 relay_log_recovery=ON
156 #innodb_additional_mem_pool_size = 20M
157 # Set .._log_file_size to 25 % of buffer pool size
158 innodb_log_file_size = 256M
159 innodb_log_buffer_size = 8M
160 innodb_flush_log_at_trx_commit = 2
161 #innodb_lock_wait_timeout = 50
162 sql_mode=""
163 [mysqldump]
164 quick
165 max_allowed_packet = 16M
166 
167 [mysql]
168 no-auto-rehash
169 # Remove the next comment character if you are not familiar with SQL
170 #safe-updates
171 
172 [myisamchk]
173 key_buffer_size = 256M
174 sort_buffer_size = 256M
175 read_buffer = 2M
176 write_buffer = 2M
177 
178 [mysqlhotcopy]
179 interactive-timeout
my.cnf

相关文章:

  • 2021-02-03
  • 2021-04-16
  • 2021-10-31
  • 2022-02-08
  • 2022-01-27
  • 2022-02-24
  • 2021-07-27
猜你喜欢
  • 2021-11-07
  • 2021-08-15
  • 2021-11-28
  • 2021-07-23
  • 2021-11-19
  • 2021-09-28
相关资源
相似解决方案