MySQL 5.5单实例 编译安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 5.5单实例 编译安装相关的知识,希望对你有一定的参考价值。
1、建立mysql账号
首先以root登录到Linux,然后执行如下命令创建MySQL组及用户
[[email protected] home]# groupadd mysql [[email protected] home]# useradd -s /sbin/nologin -g mysql -M mysql [[email protected] home]# tail -1 /etc/passwd feitian:x:811:811::/home/mysql:/sbin/nologin(/sbin/nologin表示不能登录) -s/sbin/nologin表示禁止登录 -gmysql指定属于mysql组 -M表示不创建家目录。 [[email protected] tools]# cd /home/loveyu/tools/
2、编译安装MySQL
2.1获得MySQL软件
1》通过rz上传
2》wgte 在搜狐的镜像站点中下载 http://mirrors.sohu.com/mysql/MySQL-5.7/
2.2编译[[email protected] tools]# tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
./configure \ --prefix=/usr/local/mysql \ #安装路径 --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \ #指定socket文件存放 --localstatedir=/usr/local/mysql/data \ #MySQL数据文件存放位置 --enable-assembler \ #允许使用汇编模式 --enable-thread-safe-client --with-mysqld-user=mysql \ #指定MySQL运行的系统用户 --with-big-tables--without-debug \ #使用非debug --with-pthread \ #强制使用pthread线程序库编译 --enable-assembler --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase,partition --enable-thread-safe-client \ #使用线程的方式编译客户端 --with-client-ldflags=-all-static \ #服务端使用静态库 --with-mysqld-ldflags=-all-static #客户端使用静态库 #等待完成之后make && make install
3、获取MySQL配置文件
[[email protected] mysql-5.1.72]# ll support-files/*.cnf -rw-r--r-- 1 root root 4714 May 11 08:53 support-files/my-huge.cnf -rw-r--r-- 1 root root 19763 May 11 08:53 support-files/my-innodb-heavy-4G.cnf -rw-r--r-- 1 root root 4688 May 11 08:53 support-files/my-large.cnf -rw-r--r-- 1 root root 4699 May 11 08:53 support-files/my-medium.cnf -rw-r--r-- 1 root root 2467 May 11 08:53 support-files/my-small.cnf #这里有大中小和超大三个配置文件,这里是试验环境我们最好选最小的配置文件 [[email protected] mysql-5.1.72]# /bin/cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf [[email protected] mysql-5.1.72]# ls -l /etc/my.cnf -rw-r--r-- 1 root root 19763 May 11 09:02 /etc/my.cnf
4、初始化数据库,创建MySQL数据库文件
[[email protected] data]# mkdir /usr/lacal/mysql/data -p [[email protected] data]# chown -R mysql /usr/local/mysql [[email protected] tools]# /application/mysql/scripts/mysql_install_db basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
5、启动数据库
[[email protected] mysql-5.1.72]# cp support-files/mysql.server /usr/local/mysql/bin/ [[email protected] mysql-5.1.72]# chmod 700 /usr/local/mysql/bin/mysql.server [[email protected] tools]# /usr/local/mysql/bin/mysql.server start Starting MySQL. SUCCESS! [[email protected] tools]# ps -ef|grep 3306 root 64252 63576 0 09:48 pts/0 00:00:00 grep 3306 [[email protected] mysql-test]# /usr/local/mysql/bin/mysqld_safe & [1] 64731 [[email protected] mysql]# 170511 11:50:09 mysqld_safe Logging to ‘/var/log/mysqld.log‘. 170511 11:50:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
6、配置MySQL命令全局使用路径(/etc/profile)
PATH=$PATH:/usr/bin/mysql
7、配置/etc/init.d/mysqld start 的方式启动数据库
[[email protected] mysql-5.1.72]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql-5.1.72]# chmod 700 /etc/init.d/mysqld [[email protected] mysql-5.1.72]# /etc/init.d/mysqld restart Shutting down MySQL..... SUCCESS! Starting MySQL. SUCCESS!
8、设置开机自启
[[email protected] mysql-5.1.72]# chkconfig --add mysqld [[email protected] mysql-5.1.72]# chkconfig mysqld on 或者放入rc.local中
9、登陆MySQL数据库 测试
9.1为root增加密码
[[email protected] mysql-5.1.72]# mysqladmin -u root password ‘fenghui‘ [[email protected] mysql-5.1.72]# mysql ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
9.2删除多余用户
mysql> select user,host from mysql.user; +------+-----------+ |user | host | +------+-----------+ |root | 127.0.0.1| | | feitian | |root | feitian | | | localhost| |root | localhost| +------+-----------+ 5 rows in set (0.00 sec) mysql> drop user ""@localhost;Query OK, 0 rows affected (0.00 sec) mysql> drop user ""@feitian;Query OK, 0 rows affected (0.00 sec) mysql> drop user [email protected];Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user; +------+-----------+ |user | host | +------+-----------+ |root |127.0.0.1 | |root | localhost| +------+-----------+ 2 rows in set (0.00 sec) 如果用户名中还有大写字母,则用以下命令删除 delete from mysql.user while user="" and host="大写的用户名"
错误总结:如果刚装完数据库启动时出现如下出现错误,一般来说可以重新初始化数据文件即可,要将数据文件全部删除。
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
本文出自 “13122323” 博客,请务必保留此出处http://13132323.blog.51cto.com/13122323/1952012
以上是关于MySQL 5.5单实例 编译安装的主要内容,如果未能解决你的问题,请参考以下文章