Its better to use Docker for this now:
docker container create \
--name mysql-01 \
-p 13306:3306 \
-e MYSQL_ROOT_PASSWORD="$(openssl rand -base64 8)" \
-e MYSQL_DATABASE=mydb \
-e MYSQL_USER=my_sa \
-e MYSQL_PASSWORD="$(openssl rand -base64 8)" \
mysql:8.0.30 \
--default-authentication-plugin=mysql_native_password
1) Download:
http://dev.mysql.com/downloads/file/?id=459872
2) If you install with default location, this would get installed in:
/usr/local/mysql
After install, you will get a password, note that.
3) sudo touch /usr/local/mysql/data/[hostname].local.pid (type hostname on bash to get your hostname)
4) Start MySql:
sudo /usr/local/mysql/support-files/mysql.server start
5) Connect to the server:
sudo /usr/local/mysql/bin/mysql –password=[give the password that you got after installation and put it in quotes]
On the mysql prompt:
Change your password:
set password = password(‘password’);
Create user:
CREATE USER guest@localhost;
GRANT ALL PRIVILEGES ON *.* TO guest@localhost;
to Create DB:
create database dmp;
to see list of Dbs:
show databases;
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON dmp.*
-> TO guest@localhost;
mysql>quit to quit
6) To access DB using guest:
/usr/local/mysql/bin/mysql -h localhost -u guest dmp
- to restore a db from a .sql file I did this:
./mysql -h localhost -u guest mydb < my_sql_dmp.sql
[ref: https://www.howtoforge.com/faq/howto-restore-a-mysql-database-from-an-sql-dump]
- to count # of rows in a table do:
- select count(*) from <db>.<table>;
- to get schema of a table do:
- 10. mysql> describe <db>.<table>;
+——-+————–+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——-+————–+——+—–+———+——-+
| name | varchar(200) | YES | | NULL | |
| Descr | char(40) | YES | | NULL | |
| Geom | geometry | YES | | NULL | |
+——-+————–+——+—–+———+——-+
3 rows in set (0.00 sec) - to select top 10 rows:
mysql>select name,Descr from <db>.<table> limit 10;
Further Reading: http://www.plumcreek.us/mysql/