How to Import All CSV Files in Directory in MySQL via Bash

Create a file import.sh and make it executable Paste following code in file mysqluser='root' mysqlpass='password' mysqldb='database_name' tablename='mysql_table_name' DIRECTORY='input_directory' for csv in $DIRECTORY/*.csv; do echo "Loading $csv" mysql -u $mysqluser --password=$mysqlpass -D $mysqldb -e "LOAD DATA INFILE '$csv' IGNORE INTO TABLE $tablename FIELDS TERMINATED BY '\t' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;" done

November 11, 2021 · 1 min · 56 words · Saqib Razzaq

How to quickly login to MySQL using Bash

I know this method isn’t the most secure way. But when I’m working on personal projects, it gets annoying having to enter credentials every time. Hence, I put together this little script to quickly log me in. I create file mysql.sh with following contents mysql -u username --password='password_here'

November 11, 2021 · 1 min · 48 words · Saqib Razzaq

MySQL Cheatsheet

copy a table with schema, indexes and data First, copy the table with indexes CREATE TABLE new_name LIKE table_to_copy; Then copy the data by running INSERT INTO new_name SELECT * FROM table_to_copy; create BTREE Indexes CREATE INDEX index_name ON table_name (column1, column2, ...); create FULLTEXT indexes ALTER TABLE `TableName` ADD FULLTEXT INDEX `IndexName` (`ColumnName`); create new user and give all privilages CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'user'@'localhost'; create or drop multiple indexes in same query Create multiple indexes ...

September 1, 2021 · 2 min · 261 words · Saqib Razzaq

How to use Mysql CLI in xampp

I love working with Linux and CLI. It helps boost speed to a great extent and it feels like Windows’ xampp often limits that because I mostly tend to avoid using command line. I’m finally writing this to change that and be equally as proficient on Windows. MySQL Bin Location {$xampp}/mysql/bin/mysql.exe Mysqldump Bin Location {$xampp}/mysql/bin/mysqldump.exe How to import and export files Import files Login to mysql by running {$xampp}/mysql/bin/mysql.exe -u user -p Select database by running use {$database_name} Import a file by running source {$path_to_file.sql} Export files Export a table by running mysql\bin\mysqldump.exe -u root -p database_name table > table.sql

December 11, 2020 · 1 min · 100 words · Saqib Razzaq

How to run a command on multiple MySQL tables using PHP

$query = "alter table {table} drop column columnName;"; $tables = array('tableA', 'tableB'); foreach ($tables as $key => $source) { $currentQuery = str_replace('{table}', $source, $query); DB::query($currentQuery); }

November 23, 2020 · 1 min · 26 words · Saqib Razzaq

Markdown Syntax Guide

This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme. ...

March 11, 2019 · 3 min · 446 words · Hugo Authors

How to start, stop and re-index in Sphinx

Sphinx search is a tool that extends Mysql’s FULLTEXT search capabilities and brings faster more meaningful results in your control. Start /usr/bin/searchd Stop /usr/bin/searchd --stop Find status /usr/bin/searchd --status Re-index all data sudo indexer --all

October 3, 2018 · 1 min · 35 words · Saqib Razzaq