Some Useful Options. Code Sample: MySQLMonitor/Demos/Create-DB.bat

Similar documents
Backing up or Exporting Databases Using mysqldump

BMC Remedy AR System change ID utility

Bitnami MariaDB for Huawei Enterprise Cloud

User's Guide c-treeace SQL Explorer

Bitnami MySQL for Huawei Enterprise Cloud

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting

The Two Stages of Access Control

DENICOMP SYSTEMS Copyright? 2003 Denicomp Systems All rights reserved.

How do I configure my LPL client to use SSL for incoming mail?

Creative assets management. MySQL Install Guide

Review of Fundamentals

Kaivos User Guide Getting a database account 2

Manual Shell Script Linux If Not Equals. Statement >>>CLICK HERE<<<

Contents Upgrading BFInventory iii

Using MySQL on the Winthrop Linux Systems

MassTransit 6.0 Installation Guide for Enterprise and Professional Servers on Macintosh

Installing MySQL Database On Linux

Administration Manual

Lab I: Using tcpdump and Wireshark

HP Intelligent Management Center v7.1 MySQL 5.6 Installation and Configuration Guide (Windows)

Exploring the Microsoft Access User Interface and Exploring Navicat and Sequel Pro, and refer to chapter 5 of The Data Journalist.

How to recover a lost administrator password?

Mastering Linux. Paul S. Wang. CRC Press. Taylor & Francis Group. Taylor & Francis Croup an informa business. A CHAPMAN St HALL BOOK

Using the Command-Line Interface

Infotek Solutions Inc.

12d Synergy Server Installation Guide

Model Question Paper. Credits: 4 Marks: 140

MML Command Overview

This page intentionally left blank

5/20/2007. Touring Essential Programs

Unix SQL Connection Option

Workspace Administrator Help File

Using the aregcmd Commands

Orgnazition of This Part

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Copyright Yellowfin International pty ltd

Locate your Advanced Tools and Applications

Performance Best Practices Paper for IBM Tivoli Directory Integrator v6.1 and v6.1.1

15 practical examples of using commands Mysqladmin to administer a MySQL server Wednesday, 17 March :23

Like all programming models, MySQL identifiers follow certain rules and conventions.

Agiloft Installation Guide

DiskSavvy Disk Space Analyzer. DiskSavvy DISK SPACE ANALYZER. User Manual. Version Dec Flexense Ltd.

Ftp Command Line Manual Windows Example Port 22

Installation of Perl and BioPerl with modules for MySQL databases (Windows XP)

Yellowfin Custom Installer Guide

Provider: MySQLAB Web page:

SURVEYOR/400. Users Guide. Copyright , LINOMA SOFTWARE LINOMA SOFTWARE is a division of LINOMA GROUP, Inc.

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

MEDIASEAL Encryptor Client Manual

ELODEA USER'S GUIDE HOW TO SETUP, CONFIGURE AND USE ELODEA

Introduction: What is Unix?

Configuring the Oracle Network Environment. Copyright 2009, Oracle. All rights reserved.

DCLI User's Guide. Data Center Command-Line Interface

Step by Step Guide Domain Security Pro

Part I. UNIX Workshop Series: Quick-Start

One Identity Quick Connect for Base Systems 2.4. Administrator Guide

for Q-CHECKER Text version 15-Feb-16 4:49 PM

DCLI User's Guide. Data Center Command-Line Interface 2.9.1

Installation Guide. EventTracker Enterprise. Install Guide Centre Park Drive Publication Date: Aug 03, U.S. Toll Free:

Administration Manual

National Fire Incident Reporting System (NFIRS 5.0) Configuration Tool User's Guide

Mysql Create Schema From Sql File Command Line Windows

Sysinternals DebugView

'information_schema' When Using Lock Tables

Tzunami Deployer AquaLogic Exporter Guide Supports extraction of Web Components on the server and guides migration to Microsoft SharePoint.

EMS Installation. Workstation Requirements CHAPTER. EMS Lite (Windows 95/98) EMS NT (Windows NT 4.0)

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Policy Settings for Windows Server 2003 (including SP1) and Windows XP (including SP2)

BACKUP APP V7 MYSQL DATABASE BACKUP AND RESTORE FOR WINDOWS

Console Guide. Version 4.4

Technical Support Guide. ADVANTAGE Hosted Environment

Review a Sample Database Using a SQLyog MySQL GUI Tool

Log Analyzer Reference

APPENDIX 2 Customizing SAS/ASSIST Software

Basics. I think that the later is better.

v7.0 Intelligent Management Center MySQL 5.5 Installation and Configuration Guide (for Windows)

RELAIS. Installation Guide in Windows Environment

Hydra Installation Manual

User Migration Tool. User Migration Tool Prerequisites

DiskPulse DISK CHANGE MONITOR

Lab 3a Using the vi editor

QUEST Procedure Reference

Fingerprint - Database Fingerprinting

Tzunami Deployer Oracle WebCenter Interaction Exporter Guide

$HIVE_HOME/bin/hive is a shell utility which can be used to run Hive queries in either interactive or batch mode.

Using Stata at WRDS. This document demonstrates how to connect Stata on a Windows PC with WRDS data.

DCLI User's Guide. Modified on 20 SEP 2018 Data Center Command-Line Interface

MassTransit Server Installation Guide for Windows

Manual Script Windows Batch If Condition. Syntax >>>CLICK HERE<<<

Instructor s Notes Web Data Management Web Client/Server Concepts. Web Data Management Web Client/Server Concepts

UNIX Essentials Featuring Solaris 10 Op System

Chapter 5. Exploring Navicat and Sequel Pro

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

DupScout DUPLICATE FILES FINDER

PHPRad. PHPRad At a Glance. This tutorial will show you basic functionalities in PHPRad and

Using the Web-Browser and CLI Interfaces

SiteBuilder v for Windows

Integration Services. Creating an ETL Solution with SSIS. Module Overview. Introduction to ETL with SSIS Implementing Data Flow

Tzunami Deployer Oracle WebCenter Interaction Exporter Guide

Short List of MySQL Commands

Transcription:

The command interpreter - mysql allows for interactive execution of SQL commands and for many routine and administrative tasks. At the launch of mysql, numerous options can be specified to manage formatting, outputs and other program controls. - The mysql command - Authentication parameters for user name and password - One can specify a name for an existing database, where the database becomes the default database to run commands on - same as saying USE databasename. If mysql immediately terminates, possibly with an error message such as Access denied for user sakilaadmin, then either access to MySQL is completely denied to user sakilaadmin, or it is protected by a password. In either case you must invoke mysql with the options -u name and -p:. Syntax mysql [options] [databasename] [ < commands.sql] Some Useful Options Command Alternate Form Description -e cmd --execute=cmd Executes the given command(s) in quotes sepa --tee=filename Redirect all input and output to the specified file; only allowed in interactive --no-tee Do not use logging (default). Here are a few examples of the commands using options above. These commands are stored in batch scripts and are intended to be executed on the OS command line. One can easily execute *.bat files on Unix/Linux as well: Code Sample: MySQLMonitor/Demos/Create-DB.bat mysql -u root -p -e "CREATE DATABASE sakilakubili" 1 / 7

The monitor executes a command to create a database after prompting the user for a password. Code Sample: MySQLMonitor/Demos/Select-Tee.bat mysql -B -u sakilauser -psakila sakila --tee=" sqllog/logfile1.log" -e "SELECT * FROM category" The monitor will not prompt for a password as it is specified on the command line itself. The monitor executes a SELECT command and dumps the session output into the given log file. Note: The directory to contain the file must already be created with right permissions. Formatting and Output Options Command Alternate Form Description -B --batch Separates columns in tables by tab characters -E --vertical Show query results with columns vertically, one co -N --skip-column-names Leaves off column titles in the output of tables. -s --silent Displays less status information than in normal mo Here are a few examples of the options above: Code Sample: MySQLMonitor/Demos/Select-Tee-Tabs.bat mysql -B -N -u sakilauser -psakila sakila --tee=" sqllog/tabs-notitle.log" -e "SELECT * FROM category" perror 2 The output will now be separated using tabs (-B option) and show no column titles (-N option). As before, the monitor will not prompt for a password as it is specified on the command line itself. The monitor executes a SELECT command and dumps the session output into the given log file. Code Sample: MySQLMonitor/Demos/Select-Vertical.bat 2 / 7

mysql --vertical -u sakilauser -psakila sakila --tee="sqllog/vertical.log" -e "SELECT * FROM category" The columns will be output one on a line (--vertical option). Warning: Be careful using this option with very large tables. As seen above, the --execute or -e is a very useful option with mysql as it can be used to pass SQL statements to the server. The statements must be enclosed by single or double quotation marks. If you wish to use quoted values within a statement, you should use double quotes for the statement, and single quotes for any quoted values within the statement. When this option is used, mysql executes the statements and exits. Tip: MySQL can be asked to generate XML output and even HTML tables. For example, you can use the following command to obtain a list of user accounts: Code Sample: MySQLMonitor/Demos/Show-Users.bat mysql -u root -p --execute="select User, Host FROM mysql.user" Show list of users from mysql database. Note: The long form (--execute) is followed by an equals sign (=). No default database is passed as a separate argument, as database is part of the query. Code Sample: MySQLMonitor/Demos/Execute-Multiple.bat mysql -u root -p -e "SELECT db FROM mysql.db;select VERSION();SELECT NOW()" 3 / 7

Show list of databases from mysql database, among other things. Multiple SQL statements may be passed on the command line, separated by semicolons Commands for Interactive Mode Unlike previous options which were used with the mysql at OS level, these commands are executed while using the monitor: Command Alternate Form Description \e edit Invoke external editor as EDITOR set via environment va En \g go Executes the command (equivalent to ; and Return \h help Displays a helpful list of available commands. \p print Displays the current command as it is in the buffer \c cancel Cancels input of current command and start all ove \q exit or quit \s status Displays status information about the MySQL serv \T [fn] tee [filename] Enter tee m Note :if the file already exists, then the input and output are appended to the end of th \t notee Ends tee m \u database USE database Makes the given database the default database. Executing a Script from the Monitor Use source command at the mysql command prompt to run SQL statements and mysql commands from a text file. The statements can include any statements that can be run inside of a MySQL Monitor. Executes the SQL commands contained in the file; the commands must be separated by semicolons. Create a script called " ClassFiles/MySQLMonitor/Dem os/select-category.sql " with the following SELECT statement: 4 / 7

Syntax SELECT * FROM category; At OS level, change to ClassFiles/MySQLMonitor and execute: Syntax root> mysql -uroot -p*** sakila mysql> source Demos/Select-Category.sql mysql> exit; We specify the source command followed the filename (and a file-path-prefix if file is not in the current directory). When you run the source command, the SQL statements and MySQL contained commands in the file are executed like a program. You can also use the following convention to use the source command: mysql>. Demos/Select-Category.sql The backslash and period (.) replace the word source. Execute the following SQL script logging in as sakilaadmin INTO sakila database: Code Sample: MySQLMonitor/Demos/Select-Tee.sql T sqllog/categories.log SELECT * FROM category; p t h USE mysql; SHOW TABLES; g q This SQL script will start a log, select output and then logout. Notice the similarity of name with a previous batch file. Warning: You will observe several failures, as is typical with quickly written scripts, of the errors are safe and self-explanatory. The errors will be discussed in the class. but most 5 / 7

Using the mysql Command to run a Script You can also use the mysql command at your operating system's command prompt to execute SQL statements and mysql commands in a text file, without actually launching the utility,. In addition to the regular mysql command, specify : - The (<) symbol to input STDIN to mysql command - The path and filename of the file that contains the statements. We will reuse our Select- Category.sql from before. The commands are input from a file with < file. All SQL commands can be used in this file. The commands must be followed by a semicolon. Comments are introduced with the character #. The following command is run at the operating system's command prompt: mysql -B -N -u sakilauser -psakila sakila < Select-Category.sql Note: Use double quotes to enclose the path and filename in if either name contains spaces. See Database Status The command STATUS displays of various status data information about the database: mysql> STATUS;... OR... mysql> s -------------- mysql Ver 14.12 Distrib 5.0.27, for Win32 (ia32) Connection id: 1 Current database: Current user: root@localhost SSL: Not in use Using delimiter: ; 6 / 7

Server version: 5.0.27-community-nt Protocol version: 10 Connection: localhost via TCP/IP Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 TCP port: 3306 Uptime: 5 hours 28 min 52 sec Threads: 1 Questions: 3 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 0 Queries per second avg: 0.000 -------------- MySQL Monitor Conclusion In this lesson of the MySQL tutorial, you learned about using mysql program - the MySQL client tool, also called the monitor. To continue to learn MySQL go to the top of this page and click on the next lesson in this MySQL Tutorial's Table of Contents. 7 / 7