Some problems encounted this afternoon, when trying to setup/test mysql capabilities on hypnos and virgil.
1.ERROR 2003 (HY000): Can't connect to MySQL server on 'server-name' (111)
access locally (i.e. from localhost) is fine, when trying remotely got this error. when tried with mysql++ library, got the following:
terminate called after throwing an instance of 'mysqlpp::ConnectionFailed'
what(): Can't connect to MySQL server on 'hypnos' (111)
After some searches, it appears this is just indicate network issue, not to do with mysql authentication.
TWO
most likely reasons are:
a.
with --skip-networking
on it will
not accept TCP/IP connections at all.
b. with
--bind-address=127.0.0.1
, it
will listen for TCP/IP connections only locally on the
loopback interface and will not accept remote connections.
did find skip-networking option from mysql-workbench and it's off, not find bind-add ......
今天使用PowerDesigner搭建了一个小项目,最后执行完SQL脚本时才发现有2张表的表名中间多了一个空格,查完资料,最后并惊奇发现映射文件竟然多了2个`,就是shift+数字键1的那个,也就是他在脚本是这样写的:
create table `table1`(....);
问题解决。
PS:从网上找到的资料:
作为一个Oracle DBA,MySQL很多SQL语法与Oracle的还是有很多差异的。
这里我将要在MySQL里建一个表,表名为”Test Table”, 其中一个列名为”First Name”,当我用下列SQL语句来创建此表时,MySQL返回下列错误:
mysql> create table “Test Table2″ (id int, “First Name” varchar(200));
ERROR
1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near ‘”Test Table2″ (id int, “First Name” varchar(200))’ at line 1
这个MySQL数据库是按照默认配置安装的。
那么改如何解决这个问题呢?
方法1:
使用 ` (即数字键1左边那个键)符来代替上面的双引号,就像下面
create table `Test Table2` (id ......
昨天要mysql中写存储过程发现网上有关于cursor循环且套的资料很少,现发出本人写的例子,希望能对大家有帮助.
看招:
DELIMITER $$
USE `ad_db`$$
DROP PROCEDURE IF EXISTS `test`$$
CREATE DEFINER=`root`@`%` PROCEDURE `test`()
BEGIN
/** CPA效果数 */
DECLARE _tmpId1 INT;
DECLARE _tmpId2 VARCHAR(5000);
DECLARE not_found INT DEFAULT 0 ;-- 是否未找到数据 标记
DECLARE cursor1 CURSOR FOR SELECT id from fhtest2 ; -- 测试用无业务关系
DECLARE cursor2 CURSOR FOR SELECT test from fhtest2 ;-- 测试用无业务关系
DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found = 1; -- 如果未找到数据 将标记改为不可用
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; -- 异常跳出
START TRANSACTION; -- 启动事物
INSERT INTO fhtest2 (test) VALUES (' 开始1 ');
INSERT INTO fhtest2 (test) VALUES (' 开始2 ');
OPEN cursor1; -- 启动游标1
WHILE not_found = 0 DO
FETCH cursor1 INTO _tmpId1;-- 获取数据
IF NO ......
昨天有个功能要实现排行效果,而且是随机按照某些字段的总值,但是第一个又要不一样,因为第一个人给了钱,所以要排第一。
打个比方吧,表(userinfo)中有这几个字段:username,isvalid,givedmoney,sumip,dayip,monthip,visitcount,regdate
现在要实现显示排行前10位用户,
出现在排行第一位的要是givedmoney为1的用户(表示给了钱), 而且isvalid为1(表示通过认证)
其它的9个用户呢,要在字段(sumip,dayip,monthip,visitcount)中随机选择一个作为排序的依据
这样的sql语句改怎么写呢?
下面是我的答案:
<?php
$arr_orderby=array("sumip","dayip","monthip","visitcount");
$orderby_filed=$arr_orderby(array_rand($arr_orderby) ); //得到随机字段
$sql="(select username,".$orderby_filed." from userinfo where isvali ......
用mysql_query,mysql_fetch_array()后应该要
free_result().function count_admin($where = '')
{
if($where) $where = " WHERE $where";
$result = $this->db->get_one("SELECT count(*) as num from $this->table_admin_role $where");
return $result['num'];
} ......
示例:
create procedure proc_name (in parameter integer)
begin
declare variable varchar(20);
if parameter=1 then
set variable='MySQL';
else
set variable='PHP';
end if;
insert into tb (name) values (variable);
end;
MySQL扩展也是支持存储过程的,不过只支持无返回结果的存储过程
可以使用mysqli来代替 ......
总记录数:2220; 总页数:370; 每页6 条;
首页 上一页 [6] [7] [8] [9] 10
[11] [12] [13] [14] [15] 下一页 尾页