MySQL Compile and install

Source: Internet
Author: User

1. Download

Ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.36.tar.gzftp://mirror.switch.ch/mirror/mysql /downloads/mysql-5.5/mysql-5.5.36.tar.gz.md5

2. Create MySQL database directory

2.1. Create a partition

Add a piece of hard disk

# fdisk -l     #查看所有设备的分区表信息 # fdisk /dev/sdbcommand  (m for  HELP): ncommand action   e   extended   p    primary partition  (1-4) ppartition number  (1-4):  1first cylinder   (1-2610, default 1):  using default value 1last cylinder, + cylinders or +size{k,m,g}  (1-2610, default 2610): +5g          Command  (m for help):  tselected partition 1hex  code  (type l to list codes): 8echanged system type of  partition 1 to 8e  (LINUX LVM) command  (m for help): nCommand  Action   e   extended   p   primary partition   (1-4) Ppartition number  (1-4): 2first cylinder  (655-2610, default 655): using default  value 655last cylinder, +cylinders or +size{k,m,g}  (655-2610, default  2610): +5gcommand  (m for help): tpartition number  (1-4): 2Hex  code  (type l to list codes): 8echanged system type of  partition 2 to 8e  (LINUX LVM) command  (m for help):  pDisk / dev/sdb: 21.5 gb, 21474836480 bytes255 heads, 63 sectors/track, 2610  cylindersUnits = cylinders of 16065 * 512 = 8225280  bytessector size  (logical/physical):  512 bytes / 512 bytesi/o size   (minimum/optimal):  512 bytes / 512 bytesdisk identifier: 0xba23b53e    device boot      start         end       Blocks   Id  System/dev/sdb1                1          654     5253223+  8e  Linux LVM/dev/sdb2              655         1308     5253255   8e  linux lvmcommand   (M FOR HELP):  wthe partition table has been altered! Calling ioctl ()  to re-read partition table. Syncing disks.

2.2 , creating a logical volume

# pvcreate /dev/sdb{1,2}         #创建物理卷   physical  volume  "/DEV/SDB1"  successfully created  Physical volume  "/DEV/SDB2"  successfully created# vgcreate myvg /dev/sdb{1,2}          #创建卷组   Volume group  "MYVG"  successfully created# lvcreate  -L 10G -n mylv myvg  Logical volume  "Mylv"  created          #创建逻辑卷,-l  Specifies the size,-n  specify the name of the logical volume # lvs             #产看lv   lv   vg   attr        LSize  Pool Origin Data%  Meta%   MOVE LOG CPY%SYNC CONVERT  MYLV MYVG -WI-A----- 10.00g

2.3. Format the logical volume

# mkfs.ext4-l mydata/dev/myvg/mylv-l Specify volume label

2.4. Mount the logical volume to/mydata

mkdir/mydata# vim/etc/fstablabel=mydata/mydata ext4 defaults 0 0# mount-t ext4/d Ev/myvg/mylv/mydata

2.5, create MySQL user, create MySQL data directory/mydata/data and its owner, belong to the group are MySQL

# useradd-r mysql# mkdir/mydata/data# chown-r mysql:mysql/mydata/data/#-R Recursive modification # df-lh/mydata/data/   #只显示文件系统的相关信息Filesystem Size used Avail use% mounted ON/DEV/MAPPER/MYVG-MYLV 9.8G 23M 9.2G 1%/mydata


3. Compile and install MySQL

3.1. mysql compilation installation option description

In the following table, the value of "Cmake_install_prefix" represents the installation root, the path to the other parameter values is relative to the root directory, and of course you can use the absolute path directly, as follows:

Parameter values description CMAK options

install root directory                                                  -DCMAKE_INSTALL_PREFIX=/USR

Mysqld Directory -dinstall_sbindir=sbin

Data storage Directory-dmysql_datadir=/mydata/data

Configuration file (my.cnf) directory-dsysconfdir=/etc/mysql

Plugin directory-dinstall_plugindir=lib64/mysql/plugin

Manual file Directory-dinstall_mandir=share/man

Shared Data Catalog-dinstall_sharedir=share

Library Catalog-dinstall_libdir=lib64/mysql

Header installation directory-dinstall_includedir=include/mysql

Information Document Directory-dinstall_infodir=share/info

3.2. Install MySQL

# tar -xvf mysql-5.5.36.tar.gz# cd mysql-5.5.36 # cmake . -dcmake_install_prefix=/usr/local/mysql -dmysql_datadir=/mydata/data      -DSYSCONFDIR=/etc  -DWITH_INNOBASE_STORAGE_ENGINE=1        -DWITH_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1      -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0      -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8       -ddefault_collation=utf8_general_ci# make# make install 

3.3 , Modify the MySQL installation directory of the owner and owner of the group belong to the root, belong to the group MySQL

# cd/usr/local/mysql/# chown-r. mysql. #属主. Belong to the group, the owner does not change, so omit the back. Represents the current directory

3.4. Provide live configuration files for MySQL

# cp support-files/my-small.cnf/etc/my.cnf# Vim/etc/my.cnfdatadir =/mydata/data

3.5. Provide SYSV service script for MySQL

# CP support-files/mysql.server/etc/rc.d/init.d/mysqld# chmod +x/etc/rc.d/init.d/mysqld

3.6. Add to Service list

# chkconfig--add mysqld #开启指定的服务程序 # chkconfig--list mysqld #列出chkconfig所知道的所有服务mysqld 0:off1:off2 : On3:on4:on5:on6:off

3.7. Add MySQL Full lookup command

# Vim/etc/man.config Manpath/usr/local/mysql/man

3.8, output MySQL header file to the System header file path/usr/include

# ln-sv/usr/local/mysql/include//usr/include/mysql

3.9. Output MySQL library file to System library find path

# echo '/usr/local/mysql/lib ' >/etc/ld.so.conf.d/mysql.conf # Ldconfig-v | grep MySQL

3.10, change the PATH environment variable, so that the system can directly use the relevant commands MySQL

# echo ' Export path=/usr/local/mysql/bin: $PATH ' >/etc/profile.d/mysqld.sh# source/etc/profile# echo $PATH

3.11. Initialize the database

# scripts/mysql_install_db--user=mysql--datadir=/mydata/data

3.12. Start the database and test

# service Mysqld startstarting MySQL. [OK]


4. MYSQ option

-U: User name-P: password-d: Default Open Database

5. Login Test

# mysql-uroot-p-D MySQL #登录数据库Enter password:error 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using PA Ssword:yes)

Note: At that time entered the password, so error, but is not the way if you do not enter the password will be error

Solution:

1, vim/etc/my.cnf, add "Skip-grant-tables" in the last line

2. Restart MySQL Services service MySQL restart

3, enter "Mysql-uroot-p" in the command line (do not enter a password), enter the database

4. Execute "use MySQL;" To use the MySQL database

5. Execute "Set password for [email protected]=password (' MySQL ');" (Change the root password)

6, open the MySQL directory my.ini file, delete the last line of "Skip-grant-tables", save and close the file

7. Restart MySQL Service

8. Enter "Mysql-uroot-prootadmin" on the command line

mysql> select host,user,password from user; error 1064  (42000): you have an error in your sql syntax;  check the manual that corresponds to your MySQL server  version for the right syntax to use near  ' SELECT host,user,passwd  from user '  at line 2         #如果没有执行 ' use  mysql; " command, it will show the error mysql> use mysql;mysql> select host,user,password from user;+--- -----------+------+-------------------------------------------+| host          | user | password                                    |+--------------+------+-------------------------------------------+| localhost    | root |  *e74858db86eba20bc33d0aecae8a8108c56b17fa | |  werewolf.com | root |                                             | |  127.0.0.1    | root |                                             | |  ::1          | root |                                              | |  localhost    |      |                                              | |  werewolf.com |      |                                             |+------ --------+------+-------------------------------------------+6 rows in set  (0.00 sec)


This article is from the "three elder brother" blog, please be sure to keep this source http://523958392.blog.51cto.com/9871195/1617334

MySQL Compile and install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.