Today I want to build a database for storing my records data.
My developing environment is ubuntu 18.04
Before the developing
- Install MySql on ubuntu. So mysql is seen as a server service on my ubuntu, to install it with
sudo apt-get install mysql-server
- After installed, use
sudo netstat -tap | grep mysql
to check if sql service is listening. - After verified, use default user root to login
sudo mysql
or more specificsudo mysql -h localhost -P 3306 -uroot -ppasswd
to login the server. Mysql has stored all the user info in the tables. Useshow tables from mysql;
to check. - After login,
show databases;
(always use databases with;
, mysql would not think the command is ended unless;
is put ) to get the list of all the databases generated by default. - If a new user is needed or existing user needs to be changed, to use
create user <u_name>@<u_host> identified by 'password';
oralter user ... identified with mysql_native_password by '<new_password>';
The latter could also be used to alter the verification methods for authentication methods for mysql account.
Developing
- Create a database:
create database/create schema [name];
: create one database with name, this database has no tables. - Add tables to an existing database:
use [dbname];
: Tells mysql to use daname database as the current database for subsequent statements. Thencreate table <t_name> (<row_name> type);
. Now an empty table should be created. - Insert values to the tables
insert into <t_table>(<row_name>) values(val);
thenselect <row_name> from <t_table>;
to retrieve a column back.
Questions
- Privilege: I have encountered this many times reading
\h <item>
, what is this and how would this be changed? where is this stored?