xml地图|网站地图|网站标签 [设为首页] [加入收藏]
生成MySql数据库的数据字典代码参考,6不删空用
分类:数据库

MS SQL Server未有split()函数,可是大家能够写一个Table-valued Functions定义函数[dbo].[udf_SplitStringToTable] :
图片 1

目录

Code:

图片 2图片 3

  • MySQL 5.6不删空客户的熏陶
    • 问题
    • 分析
    • 测试
      • 启航mysqld时未尝增多--skip-name-resolve
      • 启动mysqld时加上--skip-name-resolve
    • 结论

 

CREATE FUNCTION [dbo].[udf_SplitStringToTable] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @result TABLE([ID] INT IDENTITY(1,1),value NVARCHAR(MAX) 
) 
BEGIN 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
    WHILE @start < LEN(@string) + 1 
    BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1

        INSERT INTO @result (value) VALUES (SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)        
    END 
    RETURN 
END

MySQL 5.6不删空客商的影响



/**
 * 生成mysql数据字典
 */
//配置数据库
$dbserver   = "127.0.0.1";
$dbusername = "root";
$dbpassword = "xxxxxx";
$database      = "table_name";
//其他配置
$title = '数据字典';
$pdo=new PDO("mysql:host=".$dbserver.";dbname=".$database,$dbusername,$dbpassword);
$pdo->query('SET NAMES utf8');
$table_result=$pdo->query('show tables');
$arr=$table_result->fetchAll(PDO::FETCH_ASSOC);

//取得所有的表名
foreach ($arr as $val){
    $tables[]['TABLE_NAME'] =$val['Tables_in_table_name'];
}

//循环取得所有表的备注及表中列消息
foreach ($tables AS $k=>$v) {
    $sql  = 'SELECT * FROM ';
    $sql .= 'INFORMATION_SCHEMA.TABLES ';
    $sql .= 'WHERE ';
    $sql .= "table_name = '{$v['TABLE_NAME']}'  AND table_schema = '{$database}'";
    $table_result = $pdo->query($sql);
    $t=$table_result->fetchAll(PDO::FETCH_ASSOC);



    foreach($t as $v) {
        $tables[$k]['TABLE_COMMENT'] = $v['TABLE_COMMENT'];
    }
    $sql  = 'SELECT * FROM ';
    $sql .= 'INFORMATION_SCHEMA.COLUMNS ';
    $sql .= 'WHERE ';
    $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";
    $fields = array();
    $field_result = $pdo->query($sql);
    $t=$field_result->fetchAll(PDO::FETCH_ASSOC);
    foreach ($t as $v) {
        $fields[] = $v;
    }
    $tables[$k]['COLUMN'] = $fields;
}

$html = '';
//循环所有表
foreach ($tables AS $k=>$v) {
    //$html .= '<p><h2>'. $v['TABLE_COMMENT'] . ' </h2>';
    $html .= '<table  border="1" cellspacing="0" cellpadding="0" align="center">';
    $html .= '<caption>' . $v['TABLE_NAME'] .'  '. $v['TABLE_COMMENT']. '</caption>';
    $html .= '<tbody><tr><th>字段名</th><th>数据类型</th><th>默认值</th>  
     <th>允许非空</th>  
     <th>自动递增</th><th>备注</th></tr>';
    $html .= '';
    foreach ($v['COLUMN'] AS $f) {
        $html .= '<tr><td class="c1">' . $f['COLUMN_NAME'] . '</td>';
        $html .= '<td class="c2">' . $f['COLUMN_TYPE'] . '</td>';
        $html .= '<td class="c3"> ' . $f['COLUMN_DEFAULT'] . '</td>';
        $html .= '<td class="c4"> ' . $f['IS_NULLABLE'] . '</td>';
        $html .= '<td class="c5">' . ($f['EXTRA']=='auto_increment'?'是':' ') . '</td>';
        $html .= '<td class="c6"> ' . $f['COLUMN_COMMENT'] . '</td>';
        $html .= '</tr>';
    }
    $html .= '</tbody></table></p>';
}
//输出
echo '<html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <title>'.$title.'</title>  
 <style>  
 body,td,th {font-family:"宋体"; font-size:12px;}  
 table{border-collapse:collapse;border:1px solid #CCC;background:#efefef;}  
 table caption{text-align:left; background-color:#fff; line-height:2em; font-size:14px; font-weight:bold; }  
 table th{text-align:left; font-weight:bold;height:26px; line-height:26px; font-size:12px; border:1px solid #CCC;}  
 table td{height:20px; font-size:12px; border:1px solid #CCC;background-color:#fff;}  
 .c1{ width: 120px;}  
 .c2{ width: 120px;}  
 .c3{ width: 70px;}  
 .c4{ width: 80px;}  
 .c5{ width: 80px;}  
 .c6{ width: 270px;}  
 </style>  
 </head>  
 <body>';
echo '<h1 style="text-align:center;">'.$title.'</h1>';
echo $html;
echo '</body></html>';

Source Code

问题


MySQL5.6 新建本地能够登入的客户,但在本地向来登入不上,不真实的客商却能登入成功

mysql -uroot -p1234 -S /data/mysql/33562/mysql.sock  -e "select version()"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.6.39    |
+-----------+

创建了admin@'%' 用户,但在本地无法登陆,但可以远程登陆

sselect user,host,password from mysql.user;
+--------+-----------+-------------------------------------------+
| user   | host      | password                                  |
+--------+-----------+-------------------------------------------+
| root   | localhost | *A4B6157319038724E3560894F7F932C8886EBFCF |
| root   | slave58   |                                           |
| root   | 127.0.0.1 |                                           |
| root   | ::1       |                                           |
|        | localhost |                                           |
|        | slave58   |                                           |
| admin  | %         | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
| zabbix | 127.0.0.1 | *DEEF4D7D88CD046ECA02A80393B7780A63E7E789 |
| super  | 127.0.0.1 | *F85A86E6F55A370C1A115F696A9AD71A7869DB81 |
| super  | slave58   | *F85A86E6F55A370C1A115F696A9AD71A7869DB81 |
+--------+-----------+-------------------------------------------+


show grants for 'admin'@'%';

+---------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' |
+---------------------------------------------------------------------------------------------------------------+

select password('admin');
+-------------------------------------------+
| password('admin')                         |
+-------------------------------------------+
| *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
+-------------------------------------------+

以ip地址无法登陆
mysql -uadmin -padmin   -P33562 -h10.186.30.58


mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'admin'@'slave58' (using password: YES)

以socket也无法登陆
mysql -uadmin -padmin   -P33562 -S /data/mysql/33562/mysql.sock
或者
mysql -uadmin -padmin   -P33562 -h127.0.0.1

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)

不存在的用户却可以登录成功
mysql -utest  -S /data/mysql/33562/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 15
Server version: 5.6.39 MySQL Community Server (GPL)

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

  

本文由澳门新葡亰手机版发布于数据库,转载请注明出处:生成MySql数据库的数据字典代码参考,6不删空用

上一篇:通过MSSQl作业定时执行批处理BAT文件,修改语句 下一篇:没有了
猜你喜欢
热门排行
精彩图文