In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Brief introduction of installation and basic Operation of MySQL-5.7 based on CentOS7
Database (Database) is a warehouse that organizes, stores and manages data according to data structure. It came into being more than 60 years ago. With the development of information technology and market, especially after the 1990s, data management is no longer just storing and managing data, but has been transformed into a variety of data management methods needed by users. There are many types of databases, from the simplest tables that store all kinds of data to large database systems that can store massive data.
Define
To put it simply, the database itself can be regarded as an electronic filing cabinet-the place where electronic documents are stored, and users can add, intercept, update, delete and other operations on the data in the documents.
A database refers to a collection of data that is stored together in a certain way, can be shared by multiple users, has as little redundancy as possible, and is independent of the application.
Features structured storage of a large number of data information, convenient for users to effectively retrieve and access to effectively maintain the consistency and integrity of data information, reduce data redundancy to meet the application sharing and security requirements. Install the experimental environment
One CentOS7 virtual machine
[MySQL source code compilation package] MySQL-5.7.17.tar.gz
C++ runtime boost_1_59_0
# Experimental configuration
First install the relevant environment package
[root@bogon ~] # yum install-y ncurses ncurses-devel bison cmake gcc gcc-c++
Create an administrative user for MySQL
[root@bogon] # useradd-s / sbin/nologin mysql
Extract the corresponding software package (MySQL-5.7.17)
[root@bogon mysql] # tar zxvf mysql-5.7.17.tar.gz-C / opt
Extract the C++ runtime to the / usr/local/ directory
[root@bogon mysql] # tar zxvf boost_1_59_0.tar.gz-C / usr/local/
Change the directory to the / usr/local/ directory and rename the boost file
[root@bogon local] # mv boost_1_59_0/ boost
Then change to the installation directory of MySQL for compilation and configuration
[root@bogon mysql-5.7.17] # cmake\ >-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\ >-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock\ >-DSYSCONFDIR=/etc\ >-DSYSTEMD_PID_DIR=/usr/local/mysql\ > DDEFAULT_CHARSET=utf8\ >-DDEFAULT_COLLATION=utf8_general_ci\ >-DWITH_INNOBASE_STORAGE_ENGINE=1\ >-DWITH_ARCHIVE_STORAGE_ENGINE=1\ >-DWITH_BLACKHOLE_STORAGE_ENGINE=1\ >-DWITH_PERFSCHEMA_ STORAGE_ENGINE=1\ >-DMYSQL_DATADIR=/usr/local/mysql/data\ >-DWITH_BOOST=/usr/local/boost\ >-DWITH_SYSTEMD=1
After the configuration is completed, the binary conversion, compilation and installation are carried out.
[root@bogon mysql-5.7.17] # make & & make install
Modify the owner and group of the mysql working folder
[root@bogon mysql-5.7.17] # chown-R mysql:mysql / usr/local/mysql/
Modify the main configuration file of MySQL
[root@bogon mysql-5.7.17] # vim / etc/my.cnf// insert [client] port = 3306default-character-set=utf8socket = / usr/local/mysql/ MySQL. Socks [MySQL] port = 3306default-character-set=utf8socket = / usr/local/mysql/mysql.sock// at the beginning of the line to delete the configuration parameters of the original mysqld Reinsert [mysqld] user = mysqlbasedir = / usr/local/mysqldatadir = / usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = / usr/local/mysql/mysqld.pidsocket = / usr/local/mysql/mysql.sockserver-id = 1sqlflowers moveable NONGEINENGENGINESUBSTITUTION.
After modifying the above master configuration file, modify the owner and group of the configuration file
[root@bogon mysql-5.7.17] # chown mysql:mysql / etc/my.cnf
Add environment variabl
[root@bogon mysql-5.7.17] # echo'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' > > / etc/profile
[root@bogon mysql-5.7.17] # echo 'export PATH' > > / etc/profile
[root@bogon mysql-5.7.17] # source / etc/profile
Initialize the database
[root@bogon mysql-5.7.17] # cd / usr/local/mysql/ [root@bogon mysql] # [root@bogon mysql] # bin/mysqld\ >-- initialize-insecure\ >-- user=mysql\ >-- basedir=/usr/local/mysql\ >-- datadir=/usr/local/mysql/data// * * Note: an error message may be encountered here for initialization: error:too many arguments (first extra is'') Error:Aborting** solution: change the directory / usr/local/mysql/,ls to see what files are in the current directory. You should find a data folder, but the folder may be empty, so here we directly rm-rf data Delete the data folder and continue to initialize the database
Finally, copy the management script of mysqld to the system directory so that the system can recognize
[root@bogon mysql] # cp usr/lib/systemd/system/mysqld.service / usr/lib/systemd/system/ [root@bogon mysql] # systemctl daemon-reload / / Refresh Identification [root@bogon mysql] # systemctl start mysqld / / start MySQL service [root@bogon mysql] # netstat-anpt | grep 3306 / / check whether port 3306 of MySQL is open
Finally, turn off the firewall and enhanced security features, and you can set the password to log in to the database.
[root@bogon mysql] # systemctl stop firewalld.service [root@bogon mysql] # setenforce 0
At this point, you can log in to the mysql database, but there is a problem. When initializing the database, a password is generated by default, but the password is empty, so we have to set the password.
[root@bogon mysql] # mysqladmin-u root-p password "abc123" then prompts for the password: because the password generated during initialization is empty, enter directly, and then the password is set successfully. If you log in again at this time, you can log in to MySQL command line mode with the new password abc123.
Then we do the basic operation of the database.
[root@localhost ~] # mysql-u root-pEnter password: / / enter the password, and the password we set is abc123mysql > show databases / / View database information +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | school | | sys | +-+ 5 rows in set (0.01sec) mysql > create database school / / add a school database Query OK, 1 row affected (0.00 sec) mysql > use school; / / enter school database Database changedmysql > create table info (id int,name char (10), score decimal (5 sec 2)); / / create a table Query OK, 0 rows affected (0.11 sec) mysql > desc info / / View the table structure +-+-+ | Field | Type | Null | Key | Default | Extra | +-- -+-+ | id | int (11) | YES | | NULL | | name | char (10) | YES | | NULL | | score | decimal (5) | YES | | NULL | | +- -+-+ 3 rows in set (0.00 sec) mysql > select * from info / / View the data in the table Empty set (0.00 sec) / / No data has been inserted here, so it is empty mysql > insert into info (id,name,score) values. Query OK, 1 row affected (0.00 sec) mysql > insert into info (id,name,score) values. Query OK, 1 row affected (0.00 sec) mysql > insert into info (id,name,score) values (3 minicomial wangwujue 80) Query OK, 1 row affected (0.00 sec) / / insert three consecutive data mysql > select * from info / / viewing the data in the table at this time Find data stored in the table +-+ | id | name | score | +-+ | 1 | zhangsan | 75.50 | | 2 | lisi | 77.50 | | 3 | wangwu | 80.00 | +-- +-+ 3 rows in set (0.00 sec) mysql > update info set name='zhaoliu' where id=3 / / modify the name of id=3 data as zhaoliuQuery OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql > select * from info / / View the table information again +-+ | id | name | score | +-+ | 1 | zhangsan | 75.50 | | 2 | lisi | 77.50 | | 3 | zhaoliu | 80.00 | / / the original wangwu has been changed to zhaoliu+--. -+ 3 rows in set (0.00 sec) mysql > delete from info where id=2 / / Delete the data in the table Query OK of id=2, 1 row affected (0.00 sec) mysql > select * from info +-+ | id | name | score | +-+ | 1 | zhangsan | 75.50 | | 3 | zhaoliu | 80.00 | / / the data lisi of the previous id=2 here is deleted. -+ 2 rows in set (0.00 sec) mysql > drop table info / / delete info table Query OK, 0 rows affected (0.01 sec) mysql > select * from info; / / an error will be reported when viewing the table information at this time. The table does not exist because we have deleted ERROR 1146 (42S02): Table 'school.info' doesn't existmysql > show databases / / check which databases are +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | school | | sys | +-+ 5 rows in set (0.00 sec) mysql > drop database school / / delete the database Query OK of school, 0 rows affected (0.00 sec) mysql > show databases / / when you view it again You can see that the school database has been deleted +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | +-+ 4 rows in set (0.00 sec)
Please look forward to more MySQL content; MySQL indexing and transaction, MySQL database management.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.