Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tutorial on MySQL installation and basic Operation under Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Let's learn about the MySQL installation and basic operation tutorial under Linux. I believe you will benefit a lot after reading it. I hope this short article is what you want.

In order to provide richer and more powerful web application functions, we often need the support of background database, web programming and other roles.

In general small and medium-sized enterprises, the most commonly used database is MySQL,MySQL, which is a real multi-threaded, multi-user SQL database service. With its high performance, high reliability and easy to use, it has become the most popular open source database system in the field of cloud servers.

MySQL Source Code Encoding package (mysql-5.6.tar.gz):

Https://pan.baidu.com/s/1pgYHB8kyJ7U1zl2cm4XUcw

Extraction code: y8py

The version of MySQL 5.X series is the most widely used, which has good stability and compatibility.

Its official site is: http://www.mysql.com

Preparatory work:

In order to avoid port conflicts, program conflicts and other phenomena, it is recommended to check the installation of MySQL and confirm that the MySQL package installed with RPM is not used

[root@mysql /] # rpm-qa | grep mysql

If so, it is recommended to uninstall it: rpm-Q mysql-server mysql

Then you need to install the ncurses package, and it is detected that three have been installed and one is missing, so you need to mount the system CD to install it.

[root@mysql /] # rpm-qa | grep ncursesncurses-5.9-13.20130511.el7.x86_64ncurses-libs-5.9-13.20130511.el7.x86_64ncurses-base-5.9-13.20130511.el7.noarch [root@mysql /] # mount / dev/sr0 / media/ [root@mysql Packages] # rpm-ivh ncurses-devel-5.9-13.20130511.el7.x86_64.rpm warning: ncurses-devel-5.9-13.20130511.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature Key ID f4a80eb5: NOKEYPreparing... # # [100%] Updating / installing... 1:ncurses-devel-5.9-13.20130511.el7## [100%]

The MySQL 5.X series version requires cmake compilation and installation, so you need to install the cmake package first:

[root@mysql media] # tar zxf cmake-2.8.6.tar.gz-C / usr/src/ [root@mysql media] # cd / usr/src/cmake-2.8.6/ [root@mysql cmake-2.8.6] #. / configure [root@mysql cmake-2.8.6] # gmake & & gmake install # process will be very long

Source code compilation and installation:

Create a running user:

[root@mysql /] # groupadd mysql [root@mysql /] # useradd-M-s / sbin/nologin mysql-g mysql #-M does not create host directory-s specify shell environment-g specify join group

Unpack:

Extract the downloaded mysql source package:

[root@mysql media] # tar zxf mysql-5.6.36.tar.gz-C / usr/src/ [root@mysql media] # cd / usr/src/mysql-5.6.36/

Configuration:

In the corporate websites with rich content and large structure, web pages with multiple character sets may be used, and accordingly the database system should support different character set coding. During the configuration process, you can set the default character set to utf-8 and add character set support.

Note: the next command you enter needs to be case-sensitive, not even a single punctuation mark can be wrong. If you are wrong, you have to start all over again. Be sure to check patiently after writing the command.

[root@mysql mysql-5.6.36] # cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DSYSCONFDIR=/etc-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci # each "-" is preceded by a space-DWITH_EXTRA_CHARSETS=all. Each option means:-- DCMAKE_INSTALL_PREFIX: specify to install the MySQL database program to a directory-- DSYSCONFDIR: specify the initialization parameter file directory-- DDEFAULT_CHARSET. Specify the character set encoding used by default-- DDEFAULT_COLLATION: specify the character set proofreading rules used by default Utf8_general_ci is a general rule for utf-8 character sets-DWITH_EXTRA_CHARSETS: specify additional character set encodings that are supported

[root@mysql mysql-5.6.36] # make & & make install # will take a long time to compile and install

Other adjustments after installation:

Set permissions on the directory of the database:

[root@mysql] # chown-R mysql:mysql / usr/local/mysql

Create a profile:

The MariaDB database is supported by default on Centos 7 systems, so the default / etc/my.cnf configuration file of the system is the MariaDB configuration file. In the support-files folder in the source package directory, the default sample configuration file my-default.cnf file for the MySQL database is provided, so the original my.cnf file needs to be replaced with the content of the configuration file provided by MySQL before startup.

[root@mysql ~] # rm-rf / etc/my.cnf # Delete the my.cnf file under the original etc folder [root@mysql ~] # cp / usr/src/mysql-5.6.36/support-files/my-default.cnf / etc/my.cnf

Initialize the database:

Execute the initialization script mysql_install_db as user mysql to specify the data storage directory

[root@mysql] # / usr/local/mysql/scripts/mysql_install_db-user=mysql-basedir=/usr/local/mysql-datadir=/usr/local/mysql/data

Set the environment variable (to facilitate the use of the mysql command in any directory, you need to set the environment variable in / etc/profile):

[root@mysql] # echo "PATH=$PATH:/usr/local/mysql/bin" > > / etc/profile [root@mysql ~] #. / etc/profile / / effective immediately

Add as a system service:

[root@mysql ~] # cp / usr/src/mysql-5.6.36/support-files/mysql.server/usr/local/mysql/bin/mysqld.sh # copy the service script to the MySQL installation directory [root@mysql ~] # chmod + x / usr/local/mysql/bin/mysqld.sh # add execution permissions [root@mysql /] # vim / usr/lib/systemd/system/mysqld.service [Unit] Description=MySQL ServerAfter=network.target [Service] User=mysql # specify the user account under which the program runs Group=mysql # specify the group account under which the program runs Type=forkingPIDFile=/usr/local/mysql/data/mysql.com.pid # Note enter the hostname before pid Before typing, check the host name ExecStart=/usr/local/mysql/bin/mysqld.sh startExecStop=/usr/local/mysql/bin/mysqld.sh stop[ install] WantedBy=multi-user.target [root@mysql /] # systemctl enable mysqld # set up self-boot [root@mysql /] # systemctl status mysqld # check the service startup status [root@mysql /] # systemctl start mysqld # start the service

If you find it troublesome to write a configuration file, you can do it another way:

When the execute permission has been granted to / usr/local/mysql/bin/mysqld.sh, continue with the following:

[root@mysql-5.6.36] # cp / usr/local/mysql/bin/mysqld.sh / etc/init.d/mysqld [root@mysql-5.6.36] # vim / etc/init.d/mysqld

After modification, save and exit. Continue with the following command:

[root@localhost mysql-5.6.36] # chkconfig-- add mysqld # added as a system service

Log in to the database after starting the service:

Root is the default administrator for MySQL

[root@mysql /] # mysql-u root # Log in [root@mysql /] # mysqladmin-u root password 123456 # if you don't have a password [root@mysql /] # mysqladmin-u root-p password 654321 # change the password for the first time First enter the new password Enter password: # enter the old password [root@mysql /] # mysql-u root-p # login with the password Enter password: # enter the password [root@mysql /] # mysql-u root-p. / / omit part of the content mysql > status # View the basic information of the current database mysql > exit # exit the MySQL operating environment ouit can also Bye

See which libraries are available in MySQL:

Mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | test | +-+ 4 rows in set (0.03 sec)

See which tables are in the database:

Mysql > use mysql;Database changedmysql > show tables;+--+ | Tables_in_mysql | +-+ | columns_priv | | db | | time_zone_name |. / / omit part of the content | time_zone_transition | | time_zone_transition_type | | user | +-+ 28 rows in set (0.00 sec)

View the structure of the table:

Mysql > describe user +-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | name | char (16) | YES | | NULL | xingbie | char (10) | YES | | NULL | | nianling | int (11) | YES | | NULL | | +-+-+ 3 rows in set (0.01sec)

Create a new database:

Mysql > create database users

Create a new table:

Mysql > use users;mysql > create table user (name char (16), xingbie char (10), nianling int)

Delete a data table:

Mysql > drop table user;Query OK, 0 rows affected (0.01 sec)

Delete a database:

Mysql > drop database users;Query OK, 0 rows affected (0.00 sec)

Manage the data records in the table:

Insert data record:

Insert into table name (field one, field two,...) values (value of field one, value of field two,....) mysql > insert into user (name,xingbie,nianling) values ('zhangsan','nan','25')

Query data records:

Mysql > select * from user;+-+ | name | xingbie | nianling | +-+ | zhangsan | nan | 25 | +-+ 1 row in set (0.00 sec)

Modify the data record:

Update table name set field name = 'modified field value' where conditional expression mysql > update user set nianling='20' where name='zhangsan'

Delete data records:

Delete from table name where conditional expression; mysql > delete from user where name='zhangsan'

Database user authorization:

Grant authority

Grant permission list on library name. Table name to user @ source address identified by 'password'; mysql > grant select on users.user to zhangsan@localhost identified by '123456'

The following points should be noted when using the GRANT statement:

View permissions:

Show grants for user name @ source address; show grants for 'zhangsan'@'localhost'

Revoke permissions:

Revoke permission list on database name. Table name from user name @ Source address

Revoke all on test.user from 'zhangsan'@'localhost'

After reading this article on MySQL installation and basic operation under Linux, many readers will want to know more about it. For more industry information, you can follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report