In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following content mainly brings you a detailed explanation of the methods of operating mysql in shell. The knowledge mentioned here, which is slightly different from books, is summarized by professional and technical personnel in the process of contact with users, and has a certain value of experience sharing. I hope to bring help to the majority of readers.
The sql statement of MySQL-hhostname-Pport-uusername-ppassword-e related mysql can manipulate the method of mysql in shell without running mysql at the prompt of mysql.
#! / bin/bash
HOSTNAME= "192.168.111.84" # Database Information
PORT= "3306"
USERNAME= "root"
PASSWORD= ""
DBNAME= "test_db_test" # Database name
Name of the table in the TABLENAME= "test_table_test" # database
# create a database
Create_db_sql= "create database IF NOT EXISTS ${DBNAME}"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD}-e "${create_db_sql}"
# create a table
Create_table_sql= "create table IF NOT EXISTS ${TABLENAME} (name varchar (20), id int (11) default 0)"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${create_table_sql}"
# insert data
Insert_sql= "insert into ${TABLENAME} values ('billchen',2)"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${insert_sql}"
# query
Select_sql= "select * from ${TABLENAME}"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${select_sql}"
# updating data
Update_sql= "update ${TABLENAME} set id=3"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${update_sql}"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${select_sql}"
# Delete data
Delete_sql= "delete from ${TABLENAME}"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${delete_sql}"
Mysql-h$ {HOSTNAME}-P$ {PORT}-u$ {USERNAME}-p$ {PASSWORD} ${DBNAME}-e "${select_sql}"
For the above detailed explanation of how to operate mysql in shell, if you have more information, you can continue to pay attention to the innovation of our industry. If you need professional solutions, you can contact the pre-sales and after-sales on the official website. I hope this article can bring you some knowledge updates.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.