mysql的编译安装
1、下载
ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.36.tar.gz ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.36.tar.gz.md5
2、创建mysql数据库目录
2.1、创建分区
添加一块硬盘
# fdisk -l #查看所有设备的分区表信息 # fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (655-2610, default 655): Using default value 655 Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xba23b53e Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 8e Linux LVM /dev/sdb2 655 1308 5253255 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
2.2、创建逻辑卷
# 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 指定大小,-n 指定逻辑卷的名称 # lvs #产看lv LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv myvg -wi-a----- 10.00g
2.3、格式化逻辑卷
# mkfs.ext4 -L Mydata /dev/myvg/mylv -L 指定卷标
2.4、将逻辑卷挂载到/mydata
mkdir /mydata # vim /etc/fstab LABEL=Mydata /mydata ext4 defaults 0 0 # mount -t ext4 /dev/myvg/mylv /mydata
2.5、创建mysql用户,创建mysql数据目录/mydata/data且其属主、属组均为mysql
# useradd -r mysql # mkdir /mydata/data # chown -R mysql:mysql /mydata/data/ # -R 递归修改 # df -lh /mydata/data/ #只显示文件系统的相关信息 Filesystem Size Used Avail Use% Mounted on /dev/mapper/myvg-mylv 9.8G 23M 9.2G 1% /mydata
3、编译安装mysql
3.1、mysql编译安装选项说明
在下表中,“CMAKE_INSTALL_PREFIX”的值表示的是安装根目录,其他参数值的路径都是相对于根目录的,当然你也可以直接使用绝对路径,具体如下:
参数值说明 CMak选项
安装根目录 -DCMAKE_INSTALL_PREFIX=/usr
mysqld目录 -DINSTALL_SBINDIR=sbin
数据存储目录 -DMYSQL_DATADIR=/mydata/data
配置文件(my.cnf)目录 -DSYSCONFDIR=/etc/mysql
插件目录 -DINSTALL_PLUGINDIR=lib64/mysql/plugin
手册文件目录 -DINSTALL_MANDIR=share/man
共享数据目录 -DINSTALL_SHAREDIR=share
Library库目录 -DINSTALL_LIBDIR=lib64/mysql
Header安装目录 -DINSTALL_INCLUDEDIR=include/mysql
信息文档目录 -DINSTALL_INFODIR=share/info
3.2、安装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 、修改mysql安装目录的属主和属组属主为root,属组mysql
# cd /usr/local/mysql/ # chown -R .mysql . #属主.属组,属主不改,所以省略 后面的.表示当前目录
3.4、为mysql提供住配置文件
# cp support-files/my-small.cnf /etc/my.cnf # vim /etc/my.cnf datadir = /mydata/data
3.5、为mysql提供sysv服务脚本
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld # chmod +x /etc/rc.d/init.d/mysqld
3.6、添加至服务列表
# chkconfig --add mysqld #开启指定的服务程序 # chkconfig --list mysqld #列出chkconfig所知道的所有服务 mysqld 0:off1:off2:on3:on4:on5:on6:off
3.7、添加mysql的满查找命令
# vim /etc/man.config MANPATH /usr/local/mysql/man
3.8、输出mysql的头文件至系统头文件路径/usr/include
# ln -sv /usr/local/mysql/include/ /usr/include/mysql
3.9、输出mysql的库文件到系统库查找路径
# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf # ldconfig -v | grep mysql
3.10、改PATH环境变量,让系统可以直接使用mysql的相关命令
# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysqld.sh # source /etc/profile # echo $PATH
3.11、初始化数据库
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
3.12、启动数据库并测试
# service mysqld start Starting MySQL.. [ OK ]
4、mysq选项
-u : 用户名 -p : 密码 -D : 默认打开的数据库
5、登录测试
# mysql -uroot -p -D mysql #登录数据库 Enter password: ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
注:当时输入了密码,所以报错了,但是不是道如果不输入密码会不会报错
解决方案:
1、vim /etc/my.cnf,在最后一行添加“skip-grant-tables”
2、重启MySQL服务 service mysql restart
3、在命令行中输入“mysql -uroot -p”(不输入密码),回车即可进入数据库
4、执行“use mysql;”才能使用mysql数据库
5、执行“set password for root@localhost=password(‘mysql‘);”(修改root的密码)
6、打开MySQL目录下的my.ini文件,删除最后一行的“skip-grant-tables”,保存并关闭文件
7、重启MySQL服务
8、在命令行中输入“mysql -uroot -prootadmin”
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;”命令,就会显示错误了 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)
本文出自 “三哥” 博客,请务必保留此出处http://523958392.blog.51cto.com/9871195/1617334
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。