-
Notifications
You must be signed in to change notification settings - Fork 40
/
01-mysql.sh
59 lines (46 loc) · 1.57 KB
/
01-mysql.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
####
docker run --rm -it -v $(pwd)/databases:/usr/databases ubuntu:latest bash
# Install MySQL from root user
apt update && apt full-upgrade -y
apt install mysql-server -y
service mysql start # or 'systemctl start mysql' if systemd is installed
# Connect to mysql interactive shell
mysql
# To allow remote connections from root user to mysql server
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'P@ssw0rd';
# to list the current databases
SHOW DATABASES;
# to check the folder where the databases are stored
SHOW VARIABLES WHERE Variable_name = 'datadir';
# to create a database called testdb
CREATE DATABASE testdb;
# to create a table called tbl1
USE testdb;
CREATE TABLE tbl1 (id INT, name VARCHAR(20));
exit
# Check the file structure after creating the database and the table
cd /var/lib/mysql
ls -l testdb
# To restore a database called 'sakila' from a dump file
# Download the dump file from https://dev.mysql.com/doc/index-other.html
# make sure to download the schema and data files
# make sure to change the path to the dump file
SOURCE /usr/databases/sakila-db/sakila-schema.sql;
USE sakila;
SOURCE /usr/databases/sakila-db/sakila-data.sql;
SHOW TABLES FROM sakila;
SELECT * FROM actor LIMIT 10;
DESCRIBE actor;
SHOW COLUMNS FROM actor;
SHOW CREATE TABLE actor\G
####
# cleanup
sudo apt remove mysql-server -y
sudo apt autoremove -y
####
# clone repo
git clone https://github.com/ahmedsami76/sql.git
cd sql
# Use Docker
docker run -d -v /var/run/docker.sock:/tmp/docker.sock -v /etc/hosts:/tmp/hosts asami76/docker-hoster
docker-compose -f mysql.yml up -d