导航:首页 > 编程系统 > sql语句linux中

sql语句linux中

发布时间:2024-10-05 00:27:43

『壹』 linux下面安装oracle后,sql语句怎么输入

1,进入sqlplus:
sqlplus /nolog
2,以sysdba的身份连接到数据库,并启动Oracle数据库引擎:
SQL> conn /as sysdba
SQL> startup
3,退出sqlplus,运行Listener
SQL> exit
$ lsnrctl start
这样数据库的版TNS也启动了,可权以通过网络连接数据库了。一般情况下就启动这两个就够了,如果想用Oracle提供的EM来管理Oracle的话还需要启动EM控制台,运行如下命令:
$ emctl start dbconsole
若是要登录用户的话
4 sqlplus userid/passwd@orcl
5 创建一个用户
create user user01 identified by passwd;
grant connect,resource to user01 ;
grant create session to user01 ;
grant imp_full_database to user01 ;
6 可以在客户端 导入备份的数据

『贰』 Linux下如何运行sql脚本

Linux运行sql脚本的具体操作步骤如下:

1、使用shell工具登陆到安装postgresql的服务器,切换到postgres用户,postgresql默认的操作用户,命令是:su - postgres,查看当前路径是/var/lib/psql,创建一个test.sql脚本文件,命令是:vim test.sql。

『叁』 linux系统下怎么在终端运行sql语句

主要有以下几种方法:
1、将SQL语句直接嵌入到shell脚本文件中
代码如下:

--演示环境
[root@SZDB ~]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m
root@localhost[(none)]> show variables like 'version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5.6.12-log |
+---------------+------------+

[root@SZDB ~]# more shell_call_sql1.sh
#!/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/temp.log
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/temp.log>>${LOG}
echo "script executed successful.">>${LOG}
exit;

[root@SZDB ~]# ./shell_call_sql1.sh
Logging to file '/tmp/temp.log'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled.

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

代码如下:

[root@SZDB ~]# more temp.sql
tee /tmp/temp.log
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/temp.sql"
Logging to file '/tmp/temp.log'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled.

3、使用管道符调用SQL文件
代码如下:

[root@SZDB ~]# mysql -uroot -p123456 </root/temp.sql
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.
#使用管道符调用SQL文件以及输出日志
[root@SZDB ~]# mysql -uroot -p123456 </root/temp.sql >/tmp/temp.log
[root@SZDB ~]# more /tmp/temp.log
Logging to file '/tmp/temp.log'
id val
1 jack
2 robin
3 mark
Outfile disabled.

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

代码如下:

[root@SZDB ~]# more shell_call_sql2.sh
#!/bin/bash
mysql -uroot -p123456 <<EOF
source /root/temp.sql;
select current_date();
delete from tempdb.tb_tmp where id=3;
select * from tempdb.tb_tmp where id=2;
EOF
exit;
[root@SZDB ~]# ./shell_call_sql2.sh
Logging to file '/tmp/temp.log'
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_sql3.sh
#!/bin/bash
cmd="select count(*) from tempdb.tb_tmp"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit
[root@SZDB ~]# ./shell_call_sql3.sh
Warning: Using a password on the command line interface can be insecure.
Current count is : 3

[root@SZDB ~]# echo "select count(*) from tempdb.tb_tmp"|mysql -uroot -p123456 -s
3

[root@SZDB ~]# more shell_call_sql4.sh
#!/bin/bash
id=1
cmd="select count(*) from tempdb.tb_tmp where id=${id}"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit

[root@SZDB ~]# ./shell_call_sql4.sh
Current count is : 1

『肆』 谁告诉我Linux简单常用命令以及SQL语句select from where的用法、SQL语句用汉语把意思表达清楚在举例

linux常用操作命令:ls命令:(显示指定工作目录下的内容),cd(切换目录内),pwd(显示当前工作目录的绝对路容径),clear(清除屏幕上的信息),mkdir(创建目录),rmdir(删除目录),rm(删除不需要的文件),cp(复制),mv(重命名),cat(查看文件内容), find(查找指定目录下的文件),shutdown -h now 关机;shutdown -r now/reboot 重启 halt 停机

SELECT:指定要现实的属性列
FROM:指定查询对象
WHERE:指定查询条件
例如:查询职称为“讲师”的所有教师的基本工资和津贴
SELECT 姓名,基本工资,津贴
FROM 教师基本信息表,工资表
WHERE 教师基本信息表.职工编号=工资表.职工编号and职称="讲师"
应该够清楚了吧?

『伍』 在linux命令行中执行sql查询出现乱码

select userenv('language') from al;
先确认Oracle的字符集,sqlplus登录Oracle后执行语句:

select userenv('language') from al;

返回值例如:AMERICAN_AMERICA.ZHS16GBK

export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
修改Linux的NLS_LANG环境变量,修改Oracle指定的内Linux用户下面“.base_profile”文件,加容入如下:

export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"

用Linux命令“source ~/.base_profile”或者重启,使环境变量设置生效;查看环境变量的Linux命令为“echo $NLS_LANG”。

『陆』 linux连接数据库命令linux数据库连接命令

linux中查看路由命令?

查看路由命令:

1、首先连接上linux主机,进入命令行状态。

2、在命令行下输入:route-n,再按回车。

3、此时会打印出所有的路由表供查看

linux怎样连接oracle数据库?

步骤如下:

1、通过SSH或者SecureCRTPortable等可以直接连接Linux操作系统的软件,连接到Linux系统。这里我使用的是SecureCRTPortable。

2、这里先将用户切换到Oracle。当显示为$时,说明切换成功。命令:su-oracle注意事项:一定要注意su后和-后都有空格。

3、切换到Oracle用户之后,登录到到sqlplus。首先使用dba权限登录到sqlplus。命令:sqlplus/assysdba

4、在sqlplus中,使用conn连接一下具体想要操作的数据库用户。命令:connusername/password显示connected表示连接成功。

5、在SQL>中输入想要进行操作的sql语句,以一个单表查询为例进行演示:sql语句:select*fromtablename。

linux系统telnet命令应该怎么用?

利用telnet连接linux服务器需要确保:windows客户端开启telnet功能、linux服务器开启telnet服务

首先,linux服务器开启telnet服务:

许多linux系统在默认情况下是不安装telnet服务的。在此介绍yum安装telnet服务,它的优点是联网条件下能够自动检查安装包的依赖文件。

1.输入yuminstall-ytelnet-server命令安装telnet服务。出现complete,代表安装完成。

2.使用命令vi/etc/xinetd.d/telnet编辑telnet配置文件,将disable的值改成no,保存。

3.重启xinetd服务,使得telnet配置生效。命令:servicexinetrestart。

4.在linux服务器上打开telnet协议的23端口。命令vi/etc/sysconfig/iptables,添加代码-ainput-mstate--statenew-mtcp-ptcp--dport23-jaccept,保存。

5.重启iptables,使得防火墙策略生效。

然后,windows客户端开启telnet功能:

1.依次点击开始菜单-->控制面板-->程序和功能-->打开或关闭windows功能。

2.在弹出的windows功能对话框中勾选telnet客户端,点击确定。

最后,windows上点击开始菜单,在搜索框中输入cmd,回车进入dos界面。

输入命令:telnet+linux服务器ip,回车进入连接界面。输入linux系统用户名密码即可成功连接。

注意:windows客户端与linux服务器端必须在同一网段上,否则无法连通。

linux测试两台电脑能否连接的命令是?

可以用ping对方的地址的方式来测试两者是否联通。

ssh框架连接数据库的五个步骤?

步骤如下:

1、通过SSH或者SecureCRTPortable等可以直接连接Linux操作系统的软件,连接到Linux系统。这里我使用的是SecureCRTPortable。

2、这里先将用户切换到Oracle。当显示为$时,说明切换成功。命令:su-oracle注意事项:一定要注意su后和-后都有空格。

3、切换到Oracle用户之后,登录到到sqlplus。首先使用dba权限登录到sqlplus。命令:sqlplus/assysdba

4、在sqlplus中,使用conn连接一下具体想要操作的数据库用户。命令:connusername/password显示connected表示连接成功。

5、在SQL>中输入想要进行操作的sql语句,以一个单表查询为例进行演示:sql语句:select*fromtablename。

阅读全文

与sql语句linux中相关的资料

热点内容
苹果restore怎么开机 浏览:561
桌面里的文件如何转到手机上 浏览:842
java虚拟机45下载 浏览:710
win10战网怎么安装出错了 浏览:279
如何利用软文来推广网站 浏览:438
app运营需要什么软件 浏览:679
json如何传递数据 浏览:896
天天炫斗新版本觉醒视频 浏览:335
微云上传不了文件夹吗 浏览:192
微信公众平台新年模板下载 浏览:593
使用java企业级技术开发大型系统 浏览:138
广安蓝桥杯青少年编程有什么用 浏览:351
sql语句linux中 浏览:856
word文件并排查看双屏 浏览:406
文件柜内容卡 浏览:997
寄文件寄到美国要多少钱 浏览:913
中国教育发布app怎么看学分 浏览:810
linux怎么给用户文件夹所有权限 浏览:113
怎么填网络 浏览:53
三星手机恢复出厂设置代码 浏览:984

友情链接