xp+iis5+php5+mysql5环境下的mysql我如何进入shell命令行

xp+iis5+php5+mysql5环境下的mysql我如何进入shell命令行,第1张

windows里面是没有shell>命令行啊。

首先,进入命令行可以用如下方法进入:

点击“开始”,再点“运行”,然后输入cmd按回车即可进入控制命令行

另外,从命令行可以用如下方法进入mysql>

cd MYSQLBINPATH

mysql -uroot -p

其中,MYSQLBINPATH是你的mysql的安装路径下的bin目录,如mysql安装在C:\Program Files\mysql5 则就是

cd C:\Program Files\mysql5

mysql -uroot -p

然后输入mysql的密码即可。

还有,再从mysql>退出来命令行可以输入exit然后回车即可。

另外,感觉你说的“我打开进入dos,出现的就是enter password,输入密码后,进入的是mysql>命令行”,这是不是你直接在“开始-》程序”里面找的进入mysql>的快捷方式,安装完mysql后会自动安装这些。这样,你进入mysql>后再推出来就直接关闭窗口了,不会切换到命令行的。

获取mysql有关的帮助信息,直接在mysql提示符下输入help即可获得有关在mysql客户端相关的帮助信息。

这个方式与Oracle SQLplus下的help 是类似的。

mysql> help

For information about MySQL products and services, visit:

>

若要将大量的数据值插入到数据库的一个或多个表中,使用insert into语句来实现将是一项无聊的工作。

1、LOAD DATA通过读取本地文件系统上的文件,可以将大量数据添加到数据库中。

mysql> LOAD DATA INFILE ‘datafiletxt’ INTO TABLE db2table_name;

mysql> LOAD DATA INFILE ‘datafiletxt’ INTO TABLE db2table_name FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘;

mysql> load data infile “filetxt” into table table_name fields terminated by ‘\t’ (sid,name);

2、还有一个mysqlimport命令可以批量增加,mysqlimport直接从文件读取批量数据。它相当于LOAD DATA语句的一个接口。

mysqlimport可以自动生成一个LOAD DATA语句,该语句把filenametxt文件中的数据装入table_name表中。

mysqlimport根据文件名导入表名,即将文件名第一个圆点前的所有字符作为表名。例如,文件classtxt被装入class表中。

例如:

mysqlimport -L -uroot -proot db01 table_nametxt;

mysqlimport -local table_name filenametxt;

3、datafiletxt内容:

“1”,”a string”,”10020″

“2”,”a string containing a , comma”,”10220″

“3”,”a string containing a \” quote”,”10220″

“4”,”a string containing a \”, quote and comma”,”10220″

4、假如你有x表,导入了一个y表,将y表数据插入x表:

insert into x select from y;

1、首先打开cmd或PowerShell,进入mysql。

2、选择或者创建一个数据库,使用了以前创建的数据库test。

3、在数据库下创建表stu,表结构如图。

4、接着向stu表插入四条数据,插入后查看该表的数据。

5、再输入sql语句 update stu set credit1=82; 就可以获取一列中的最大值了。

方法一、适合所有格式的mysql数据库,通过对数据库导出导进写个脚本定时执行:

1导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc > /存放路径/wcncsql

2导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> /存放路径/wcnc_userssql

3导出一个数据库结构 mysqldump -u wcnc -p -d --add-drop-table smgp_apps_wcnc >/存放路径/wcnc_dbsql

定义:

-d 没有数据

--add-drop-table 在每个create语句之前增加一个drop table

4导入数据库 常用source 命令 进入mysql数据库控制台:

如mysql -u root -p mysql>use 数据库

方法二、针对mysql数据表格式为MyISAM的

假如数据文件在/var/lib/mysql

那么直接写个脚本

cp -r /var/lib/mysql /备份到的文件夹路径

隔机备份用rsync增量,或定时完整备份。

1、将SQL语句直接嵌入到shell脚本文件中

复制代码 代码如下:

--演示环境

[root@SZDB ~]# more /etc/issue

CentOS release 59 (Final)

Kernel \r on an \m

root@localhost[(none)]> show variables like 'version';

+---------------+------------+

| Variable_name | Value |

+---------------+------------+

| version | 5612-log |

+---------------+------------+

[root@SZDB ~]# more shell_call_sql1sh

#!/bin/bash

# Define log

TIMESTAMP=`date +%Y%m%d%H%M%S`

LOG=call_sql_${TIMESTAMP}log

echo "Start execute sql statement at `date`" >>${LOG}

# execute sql stat

mysql -uroot -p123456 -e "

tee /tmp/templog

drop database if exists tempdb;

create database tempdb;

use tempdb

create table if not exists tb_tmp(id smallint,val varchar(20));

insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');

select from tb_tmp;

notee

quit"

echo -e "\n">>${LOG}

echo "below is output result">>${LOG}

cat /tmp/templog>>${LOG}

echo "script executed successful">>${LOG}

exit;

[root@SZDB ~]# /shell_call_sql1sh

Logging to file '/tmp/templog'

+------+-------+

| id | val |

+------+-------+

| 1 | jack |

| 2 | robin |

| 3 | mark |

+------+-------+

Outfile disabled

2、命令行调用单独的SQL文件

复制代码 代码如下:

[root@SZDB ~]# more tempsql

tee /tmp/templog

drop database if exists tempdb;

create database tempdb;

use tempdb

create table if not exists tb_tmp(id smallint,val varchar(20));

insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');

select from tb_tmp;

notee

[root@SZDB ~]# mysql -uroot -p123456 -e "source /root/tempsql"

Logging to file '/tmp/templog'

+------+-------+

| id | val |

+------+-------+

| 1 | jack |

| 2 | robin |

| 3 | mark |

+------+-------+

Outfile disabled

3、使用管道符调用SQL文件

复制代码 代码如下:

[root@SZDB ~]# mysql -uroot -p123456 </root/tempsql

Logging to file '/tmp/templog'

id val

1 jack

2 robin

3 mark

Outfile disabled

#使用管道符调用SQL文件以及输出日志

[root@SZDB ~]# mysql -uroot -p123456 </root/tempsql >/tmp/templog

[root@SZDB ~]# more /tmp/templog

Logging to file '/tmp/templog'

id val

1 jack

2 robin

3 mark

Outfile disabled

4、shell脚本中MySQL提示符下调用SQL

复制代码 代码如下:

[root@SZDB ~]# more shell_call_sql2sh

#!/bin/bash

mysql -uroot -p123456 <<EOF

source /root/tempsql;

select current_date();

delete from tempdbtb_tmp where id=3;

select from tempdbtb_tmp where id=2;

EOF

exit;

[root@SZDB ~]# /shell_call_sql2sh

Logging to file '/tmp/templog'

id val

1 jack

2 robin

3 mark

Outfile disabled

current_date()

2014-10-14

id val

2 robin

5、shell脚本中变量输入与输出

复制代码 代码如下:

[root@SZDB ~]# more shell_call_sql3sh

#!/bin/bash

cmd="select count() from tempdbtb_tmp"

cnt=$(mysql -uroot -p123456 -s -e "${cmd}")

echo "Current count is : ${cnt}"

exit

[root@SZDB ~]# /shell_call_sql3sh

Warning: Using a password on the command line interface can be insecure

Current count is : 3

[root@SZDB ~]# echo "select count() from tempdbtb_tmp"|mysql -uroot -p123456 -s

3

[root@SZDB ~]# more shell_call_sql4sh

#!/bin/bash

id=1

cmd="select count() from tempdbtb_tmp where id=${id}"

cnt=$(mysql -uroot -p123456 -s -e "${cmd}")

echo "Current count is : ${cnt}"

exit

[root@SZDB ~]# /shell_call_sql4sh

Current count is : 1

#以上脚本演示中,作抛砖引玉只用,对于输出的结果不是很规整友好,需要进一步改善和提高。

以上就是关于xp+iis5+php5+mysql5环境下的mysql我如何进入shell命令行全部的内容,包括:xp+iis5+php5+mysql5环境下的mysql我如何进入shell命令行、如何获取mysql帮助信息、shell 怎么造mysql 的大量数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9415446.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存