Linux Linux help

 

Mysql Server

1. How to install Mysql Server?

In Linux Mint, open Administration, Software Manager and search for mysql, select mysql-server and click Install.

If using apt, you can install it using sudo apt-get install which will includes the following packages:

libevent-core-2.1.7, libevent-pthreads-2.1.7, libhtml-template-perl, libmecab2, mecab-ipadic, macab-upadic-utf8, mecab-utils, mysql-client-8.0,
mysql-client-core-8.0, mysql-server-8.0, mysql-server-core-8.0,

You can also download the required packages via the Mysql Community Downloads page.

2. How to configure mysql?

You will need to modify the /etc/mysql/my.cnf file with various options required for your instance of mysql. Options come in the format option_name = value.
See mysql configuration documention about it.

3. How do I access and manage mysql?

There are three ways to manage mysql. You can you the standard command line mysql command, you can use Mysql Workbench desktop tool or web based tools
such as PHPMyAdmin.

a) Access mysql server via mysql command line. Specify -h for server name, -u for username (default is root), -p to enter a password and optional database to use.

$ mysql -h mysqlservername -u username -p [database]

4. How do I create a database?

Once you have connected to mysql server, you can now run mysql commands to create, modify, view or delete databases. Note, commands should always end with a semi-colon.

i) To list all the databases you are allowed to view or see (root or database admins can see all databases)

> show databases;

ii) To create a database, run the following command with the name of the database:

> create database dabasename;

iii) To create a table within a database with fields or columns use the following command. Use int for integers, varchar for variable length character strings.

> use databasename;

> create table tablename (fieldname type [primary key, fieldname type, ...)
E.g.
> create table contacts (contactid int primary key, firstname varchar(100), lastname varchar(100), telephone varchar(30), street varchar(100), town varchar(100));

5. How do I add users and give permissions to a database?

You can create users by using the create user command, specify the scope or ipaddress or subnet of where the user can login from and provide a password. The scope can be
the mysql server itself ,localhost or a server name in DNS, a ip address and subnet mask or a subnet with a subnet mask. You can add multiple entries for the same user for different
servers or subnets if you wish. E.g.

> create user username@localhost identified by 'password-string';

> create user username@10.1.0.0/255.255.255.0 identified by 'password-string';

To permit a user to access a database and its data, you can use the grant command, use all for all permissions or you can specify specific permissions, such as select, insert, update,
delete on a database.

>grant all on databasename.* to username@localhost with grant option;

When finished creating users, run flush privileges; which will ensire the grant tables are reloaded and ready to use immediately.