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

How to build MYSQL

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

Share

Shulou(Shulou.com)05/31 Report--

This article will explain how to build MYSQL for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Mysql installation can be divided into 1.rpm mode and 2.tar package mode, the difference between the two is similar to "one-click installation" mode, tar mode is "advanced definition", most of the enterprise installation is "advanced definition" mode.

Rpm installation

One: prerequisite preparation

1. Check if it has been installed

Rpm-qa | grep mysql

two。 Detect the availability of mysql services

Ps-ef | grep mysql

3. Check whether you can connect to the external network.

Ping www.baidu.com

4. Configure yum Feed

The built-in yum source can meet the needs. If not, you need to configure it yourself.

Two: installation steps

1. Search for the source, if you report an error, it may be that the network is down.

Yum search mysql

two。 Online installation

Yum install-y mysql-server.x86_64-server

Yum install-y mysql.x86_64-client

Three: start the service

1.service mysqld start (Note: mysqld'D' indicates the process running in the background)

two。 View the service, port number:

Ps-ef | grep mysql

Netstat-nls | grep 3306

Note: check to see the 3306 default port number, that is, mysql service startup.

Four: enter the user

After installation, regret to create a root user by default. The password is empty.

[root@hadoop001] # mysql-uroot-p

Enter password: enter directly-

Note: the generation uses interactive input password to prevent the plaintext history command from putting the password in plaintext.

Install MySQL package in tar mode

Specialized software in the enterprise will have special users to deploy and run.

Oa system oaadmin

Erp system erpadmin

Standardizing users can standardize permissions and is easy to manage.

Mysql A relational database was acquired by oracle, with a free version and a paid version.

Oracle

Postgresql

Sqlserver

Id name age

1 ruoze 18

2 20

Second: tar installation

1. In the case of networking, you can download the installation package directly from the network.

[root@sht-sgmhadoopnn-01 ~] # cd / usr/local

[root@sht-sgmhadoopnn-01 local] # wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

[root@sht-sgmhadoopnn-01 local] # wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz.md5

Here we download it with a special package.

Mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

two。 This installation is installed with a ready-made installation package.

Enter the rz command in secureCRT

1. Root users enter the directory

[root@sht-sgmhadoopnn-01 ~] # cd / usr/local

two。 Use md5 to check the integrity of the packet.

[root@sht-sgmhadoopnn-01 local] # cat mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz.md5-- MD5 value included in the original package

61affe944eff55fcf51b31e67f25dc10 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

[root@sht-sgmhadoopnn-01 local] # md5sum mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

61affe944eff55fcf51b31e67f25dc10 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

two。 Check if it has been installed

[root@sht-sgmhadoopnn-01 local] # ps-ef | grep mysqld

Root 2493 2423 0 19:48 pts/3 00:00:00 grep mysqld

[root@sht-sgmhadoopnn-01 local] # rpm-qa | grep-I mysql

3. Extract the package to the specified directory and rename it

[root@sht-sgmhadoopnn-01 local] cd / usr/local

[root@sht-sgmhadoopnn-01 local] tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz-- path is root user / usr/local

[root@sht-sgmhadoopnn-01 local] # mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql--rename the extracted package to mysql (because the mysqladmin user's home directory is / usr/loca/mysql, so after su-mysqladmin changes to the home directory, it goes directly to the extracted package directory to facilitate installation.)

4. Create a user group

[root@sht-sgmhadoopnn-01 local] # groupadd-g 101 dba

[root@sht-sgmhadoopnn-01 local] # useradd-u 514-g dba-G root-d / usr/local/mysql mysqladmin

Useradd: warning: the home directory already exists. -- be careful if users exist

Not copying any file from skel directory into it. Because the user already exists, the environment variable will not exist in the home directory.

# # if user mysqladmin is existing,please execute the following command of usermod.

# # [root@sht-sgmhadoopnn-01 local] # usermod-u 514-g dba-G root-d / usr/local/mysql

[root@sht-sgmhadoopnn-01 local] # userdel mysqladmin-delete if the user already exists

5. Create a password for the user

[root@sht-sgmhadoopnn-01 local] # id mysqladmin

Uid=514 (mysqladmin) gid=101 (dba) groups=101 (dba), 0 (root)

[root@sht-sgmhadoopnn-01 local] # passwd mysqladmin

6. Copy the environment variable .bash _ profile, etc. If ls-lart has it, this step can be omitted

# # configure copy environment variables to the home directory of mysqladmin users, and configure personal environment variables for the following steps

[root@sht-sgmhadoopnn-01 local] # cp / etc/skel/.* / usr/local/mysql-- copy the environment variables to the mysqladmin home directory

Cp: omitting directory `/ etc/skel/.'

Cp: omitting directory `/ etc/skel/..'

Cp: omitting directory `/ etc/skel/.mozilla'

6.1 configure environment variables

[mysqladmin@sht-sgmhadoopnn-01 ~] $cat .bash _ profile

# .bash _ profile

# Get the aliases and functions

If [- f ~ / .bashrc]; then

. ~ / .bashrc

Fi

# User specific environment and startup programs

Export MYSQL_HOME=/usr/local/mysql

Export PATH=$ {MYSQL_HOME} / bin:$PATH

Export PATH

Ps1= `uname-n` ":" $USER ":" $PWD ": >";-- Note that variable names should be capitalized

Export PS1

#':'is a delimiter, and each time you add an environment variable, it is placed before $PATH (the new variable is placed in front of the linux command because the execution of the linux command is searched in the order of $PATH. If the old version of the variable value is already included in the $PATH, the old version of the environment variable is preferred.), $PATH means the original environment variable + the new variable.

Make the variable effective

. .bash _ profile

Su-mysqladmin

Exit users after copying environment variables

Re-enter su-mysqladmin and you can see that the user path has been brought out at the current cursor.

7. Configure mysql main profile my.cnf (640 permissions)

The order in which to find the configuration files

# defualt start: / etc/my.cnf- > / etc/mysql/my.cnf- > SYSCONFDIR/my.cnf- > $MYSQL_HOME/my.cnf- >-- defaults-extra-file- > ~ / my.cnf

Uniformly, we assign documents in the first place.

[root@sht-sgmhadoopnn-01 mysql] # cd / etc/-- create a my.cnf under the etc directory

[root@sht-sgmhadoopnn-01 etc] # touch my.cnf

Configuration file content:

[root@sht-sgmhadoopnn-01 etc] # vi my.cnf

[client] # client configuration location

Port = 3306

Socket = / usr/local/mysql/data/mysql.sock

[mysqld] # Server configuration location

Port = 3306

Socket = / usr/local/mysql/data/mysql.sock

Skip-external-locking

Key_buffer_size = 256m

Sort_buffer_size = 2m

Read_buffer_size = 2m

Read_rnd_buffer_size = 4m

Query_cache_size= 32M

Max_allowed_packet = 16m

Myisam_sort_buffer_size=128M

Tmp_table_size=32M

Table_open_cache = 512

Thread_cache_size = 8

Wait_timeout = 86400

Interactive_timeout = 86400

Max_connections = 600,

# Try number of CPU's*2 for thread_concurrency

Thread_concurrency = 32

# isolation level and default engine

Default-storage-engine = INNODB

Transaction-isolation = READ-COMMITTED

Server-id = 1

Basedir = / usr/local/mysql

Datadir = / usr/local/mysql/data

Pid-file = / usr/local/mysql/data/hostname.pid

# open performance schema

Log-warnings

Sysdate-is-now

Binlog_format = MIXED

Log_bin_trust_function_creators=1

Log-error = / usr/local/mysql/data/hostname.err

Log-bin=/usr/local/mysql/arch/mysql-bin

# other logs

# general_log = 1

# general_log_file = / usr/local/mysql/data/general_log.err

# slow_query_log=1

# slow_query_log_file=/usr/local/mysql/data/slow_log.err

# for replication slave

# log-slave-updates

# sync_binlog = 1

# for innodb options

Innodb_data_home_dir = / usr/local/mysql/data/ # Storage data directory

Innodb_data_file_path = ibdata1:500M:autoextend

Innodb_log_group_home_dir = / usr/local/mysql/arch

Innodb_log_files_in_group = 2

Innodb_log_file_size = 200m

# Mechanical hard disk in production

# ssd disk 5000r 7200r (Volkswagen production) 10000r (Volkswagen production) 15000r conditional use Sata

# innodb_buffer_pool_size production tuning up to 8G

Innodb_buffer_pool_size = 1024m # free command to view server memory and allocate it appropriately

Innodb_additional_mem_pool_size = 50m

Innodb_log_buffer_size = 16m

Innodb_lock_wait_timeout = 100

# innodb_thread_concurrency = 0

Innodb_flush_log_at_trx_commit = 1

Innodb_locks_unsafe_for_binlog=1

# innodb io features: add for mysql5.5.8

Performance_schema

Innodb_read_io_threads=4

Innodb-write-io-threads=4

Innodb-io-capacity=200

# purge threads change default (0) to 1 for purge

Innodb_purge_threads=1

Innodb_use_native_aio=on

# case-sensitive file names and separate tablespace

Innodb_file_per_table = 1

Lower_case_table_names=1

[mysqldump]

Quick

Max_allowed_packet = 16m # maximum packet

[mysql]

No-auto-rehash

[mysqlhotcopy]

Interactive-timeout

[myisamchk]

Key_buffer_size = 256m

Sort_buffer_size = 256m

Read_buffer = 2m

Write_buffer = 2m

-

8. Change my.cnf permissions

[root@sht-sgmhadoopnn-01 local] # chown mysqladmin:dba / etc/my.cnf

[root@sht-sgmhadoopnn-01 local] # chmod 640 / etc/my.cnf

[root@sht-sgmhadoopnn-01 etc] # ll my.cnf

-rw-r- 1 mysqladmin dba 2201 Aug 25 23:09 my.cnf

9. Change the permissions of users and groups under the home directory

[root@sht-sgmhadoopnn-01 local] # chown-R mysqladmin:dba / usr/local/mysql

[root@sht-sgmhadoopnn-01 local] # chmod-R 755 / usr/local/mysql

10. Change to the mysql home directory and create the arch directory. The arch directory is specified in my.cnf.

Root@sht-sgmhadoopnn-01 local] # su-mysqladmin

[mysqladmin@sht-sgmhadoopnn-01 ~] $pwd

/ usr/local/mysql

Create an arch directory to store binlog binary archive logs mysql--maxwell--kafka--sparkstrm--hbase real time

Cd / usr/local/mysql

Mkdir arch

11. Start the installation, the script in the user directory

[mysqladmin@sht-sgmhadoopnn-01 ~] $scripts/mysql_install_db

Installing MySQL system tables..../bin/mysqld:

Error while loading shared libraries: libaio.so.1: cannot open shared object file:

No such file or directory # is missing the libaio.so package

=

Missing package workaround:

1. View version

[root@sht-sgmhadoopnn-01 local] # cat / proc/version

Linux version 2.6.18-164.11.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) # 1 SMP Wed Jan 20 07:32:21 EST 2010

two。 Check to see if there are gcc packages

[root@sht-sgmhadoopnn-01 local] # rpm-qa | grep gcc

Libgcc-4.1.2-46.el5_4.2

Libgcc-4.1.2-46.el5_4.2

3. Install the corresponding package

[root@sht-sgmhadoopnn-01 local] # yum-y install libaio

Assuming the previous installation error and installing again, you need to empty the two directory legacy files:

Rm-rf data/*

Rm-rf arch/*

=

twelve。 Start the installation, to be on the safe side, specify the execution path, there is really no need to specify.

[mysqladmin@sht-sgmhadoopnn-01 ~] $scripts/mysql_install_db\

-- user=mysqladmin\

-- basedir=/usr/local/mysql\

-- datadir=/usr/local/mysql/data

Check the data/hostname.err file carefully for errors

Or:

Scripts/mysql_install_db\

-- user=mysqladmin\

-- basedir=/usr/local/mysql\

-- datadir=/usr/local/mysql/data\

-- defaults-file=/etc/my.cnf-- specify the defaults-file method manually

Or:

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

Note: because the mysql home directory is / usr/local/mysql, and we have renamed the tar package to mysql in the previous step, when su-mysqladmin changes to the home directory, you have entered the unzipped installation package of tar, and you can see the script directory.

13. Configure mysql to boot automatically

[root@sht-sgmhadoopnn-01 ~] # cd / usr/local/mysql

# copy the service file to init.d and rename it to mysql

[root@sht-sgmhadoopnn-01 mysql] # cp support-files/mysql.server / etc/rc.d/init.d/mysql

# Grant executable permissions

[root@sht-sgmhadoopnn-01 mysql] # chmod + x / etc/rc.d/init.d/mysql

# deleting a service

[root@sht-sgmhadoopnn-01 mysql] # chkconfig-- del mysql

# re-add services

[root@sht-sgmhadoopnn-01 mysql] # chkconfig-- add mysql

# add Boot Startup Service

[root@sht-sgmhadoopnn-01 mysql] # chkconfig-- level 345 mysql on

[root@sht-sgmhadoopnn-01 mysql] # vi / etc/rc.local

#! / bin/sh

#

# This script will be executed * after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

Touch / var/lock/subsys/local

Su-mysqladmin-c "/ etc/init.d/mysql start-- federated"

-

[root@hadoop ~] # cp / usr/local/mysql/support-files/mysql.server / etc/rc.d/init.d/mysql

[root@hadoop ~] # chmod + x / etc/rc.d

Rc.d/ rc.local rc.sysinit

[root@hadoop ~] # chmod + x / etc/rc.d/init.d/mysql

[root@hadoop ~] # ll / etc/rc.d/init.d/mysql

-rwxr-xr-x 1 root root 10880 Jan 29 12:47 / etc/rc.d/init.d/mysql

-

9. Start mysql

[root@sht-sgmhadoopnn-01 mysql] # su-mysqladmin

[mysqladmin@sht-sgmhadoopnn-01 ~] $pwd

/ usr/local/mysql

[mysqladmin@sht-sgmhadoopnn-01 ~] $rm-rf my.cnf # can be retained because it is already available in the directory.

[mysqladmin@hadoop001 ~] $service mysql start # enable the service

Starting MySQL. [OK]

[mysqladmin@hadoop001 ~] $service mysql status

MySQL running (3625) [OK]

Or:

# it is also possible to start another security mode

[mysqladmin@sht-sgmhadoopnn-01 ~] $mysqld_safe & # Security mode is enabled, another mode is enabled. Enter at the cursor after execution.

[1] 11802

[mysqladmin@sht-sgmhadoopnn-01] $150825 22:53:38 mysqld_safe Logging to'/ usr/local/mysql/data/hostname.err'.

150825 22:53:38 mysqld_safe Starting mysqld daemon with databases from / usr/local/mysql/data/

150825 22:53:39 mysqld_safe mysqld from pid file / usr/local/mysql/data/hostname.pid ended

[mysqladmin@sht-sgmhadoopnn-01 ~] $which mysqld_safe

~ / bin/mysqld_safe # you can see the directory of mysqld_safe

10. View service monitoring

[mysqladmin@sht-sgmhadoopnn-01 ~] $ps-ef | grep mysqld-- mysqld, not mysql

514 6247 6219 0 17:30 pts/1 00:00:00 / bin/sh / usr/local/mysql/bin/mysqld_safe

6902 6247 2 17:30 pts/1 00:00:01 / usr/local/mysql/bin/mysqld-- basedir=/usr/local/mysql-- datadir=/usr/local/mysql/data-- plugin-dir=/usr/local/mysql/lib/plugin-- log-error=/usr/local/mysql/data/hostname.err-- pid-file=/usr/local/mysql/data/hostname.pid-- socket=/usr/local/mysql/data/mysql.sock-- port=3306 # 3306 indicates that it has been started

514 6927 6219 0 17:31 pts/1 00:00:00 grep mysqld

View monitoring

[mysqladmin@sht-sgmhadoopnn-01 ~] $netstat-tulnp | grep mysql # View port

(Not all processes could be identified, non-owned process info

Will not be shown, you would have to be root to see it all.)

Tcp 0 0: 3306: * LISTEN 11541/mysqld

[root@sht-sgmhadoopnn-01 local] # service mysql status

MySQL running (21507) [OK]

At this point, the deployment is complete

Note:

Mysql creates two users

1.root user password is empty to change password

two。 Empty user password is empty to delete the user

Login method:

# Note 1. Log in without a clear password. 2. No spaces can be added to the parameters such as Murp.

Bin/mysql-uroot-p-h227.0.0.1 # enter the password in this way is secure and will not be recorded by history

Bin/mysql-uroot-p123456-h227.0.0.1 # unsafe in this way will be recorded by history

Bin/mysql-u root-p 123456-h 127.0.0.1-P3306 # plus port number is not safe. 127.0.0.1 is your own computer ip.

11. Log in to mysql

[mysqladmin@sht-sgmhadoopnn-01] $bin/mysql-uroot-p

You can also enter the / usr/local/mysql/bin directory, where. / mysql-uroot-p indicates that mysql. / under the current path is the relative path.

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | test |

+-+

4 rows in set (0.00 sec)

twelve。 Change root password and delete empty user

Mysql > use mysql

Database changed

To be safe, there are two things to do.

1. The password for changing root is not empty.

two。 Delete empty user

Mysql > update user set password=password ('123456') where user='root'; # change the password for root users, passwodr (' 123456') is encrypted

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4 Changed: 4 Warnings: 0

Mysql > select host,user,password from user

+-- +

| | host | user | password | |

+-- +

| | localhost | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| | sht-sgmhadoopnn-01 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| | 127.0.0.1 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| |:: 1 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| | localhost |

| | sht-sgmhadoopnn-01 |

+-- +

6 rows in set (0.00 sec)

Mysql > delete from user where user=''; # Delete empty users

Mysql > select host,user,password from user

+-- +

| | host | user | password | |

+-- +

| | localhost | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| | sht-sgmhadoopnn-01 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| | 127.0.0.1 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

| |:: 1 | root | * 6340BE3C15D246B0D74BAF3F135915ED19E0069F |

+-- +

4 rows in set (0.00 sec)

# execute refresh permissions in the last step of the operation statement for user permissions

Mysql > flush privileges

13. Log in again

Bin/mysql-uroot-p-hlocalhost

14.Configure .bash _ profile # configure environment variables

[mysqladmin@sht-sgmhadoopnn-01 ~] $cat .bash _ profile

# .bash _ profile

# Get the aliases and functions

If [- f ~ / .bashrc]; then

. ~ / .bashrc

Fi

# User specific environment and startup programs

Export MYSQL_HOME=/usr/local/mysql

Export PATH=$ {MYSQL_HOME} / bin:$PATH

Export PATH

Ps1= `uname-n` ":" $USER ":" $PWD ": >";-- Note that variable names should be capitalized

Export PS1

#':'is a delimiter, and each time you add an environment variable, it is placed before $PATH (the new variable is placed in front of the linux command because the execution of the linux command is searched in the order of $PATH. If the old version of the variable value is already included in the $PATH, the old version of the environment variable is preferred.), $PATH means the original environment variable + the new variable.

Make the variable effective

. .bash _ profile

Su-mysqladmin

This is the end of the article on "how to build MYSQL". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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