源码安装mysql通用二进制包

如果以前使用操作系统本机包管理系统(如yum或apt)安装过mysql,则使用二进制文件安装时可能会遇到问题。确保以前的mysql安装已完全删除(使用包管理系统),并且任何其他文件(如旧版本的数据文件)也已删除。还应该检查配置文件,如/etc/my.cnf或/etc/mysql目录,并将其删除。
MySQL依赖于libaio库。如果未在本地安装此库,则数据目录初始化和随后的服务器启动步骤将失败。请使用相应的包管理器安装它。

实验环境:
操作系统:centos6.5
安装包:mysql-5.5.32-linux2.6-x86_64.tar.gz
下载地址:https://downloads.mysql.com/archives/get/file/mysql-5.5.32-linux2.6-x86_64.tar.gz
安装位置:/usr/local/mysql

实验步骤:
1.创建系统用户和用户组,用于调用mysql服务。
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
2.解压二进制分发包。
# tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz
计划将mysql装到/usr/local目录下,所以在/usr/local目录下做了一个软链接,连接到解压缩的mysql文件夹:
# cd /usr/local/
# ln -s src/mysql-5.5.32-linux2.6-x86_64 mysql
# ll -d mysql
lrwxrwxrwx. 1 root root 32 Sep  4 09:27 mysql -> src/mysql-5.5.32-linux2.6-x86_64
3.安装后设置与测试:
(1)修改用户和所属组。
# chown -R mysql /usr/local/mysql/
# chgrp -R mysql /usr/local/mysql/
(2)数据目录初始化。须在scripts与bin同级目录下才能执行成功,进入scripts目录执行mysql_install_db会失败。

# ls
bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
# ./scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

(3)按照上面给的提示进行操作和配置。
将support-files/mysql.server复制到/etc/init.d,便于启动,停止mysql:
# cd support-files/
# cp mysql.server /etc/init.d/
同时,将my-medium.cnf拷贝为my.cnf
# cp my-medium.cnf /etc/my.cnf

为root账户设置登录密码 123456 ,只有首次设置生效:
# ./bin/mysqladmin -u root password '123456'

为了增强安全性,可以使用mysql_secure_installation,删除测试数据库和账户:
./bin/mysql_secure_installation


至此,可以使用/etc/init.d/mysql.server start/stop进行管理。总体过程还是很简单的。

注意事项:

有时会无法启动mysql,需要查看日志,本日志位于/usr/local/mysql/data/localhost.localdomain.err,告警如下:

190911  6:09:29 [Note] Server socket created on IP: '0.0.0.0'.
190911  6:09:29 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
190911 06:09:29 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
190911 06:14:04 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
190911  6:14:04 [Note] Plugin 'FEDERATED' is disabled.
/usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist
190911  6:14:04 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

解决方法:重新目录初始化./scripts/mysql_install_db --user=mysql

4.一旦忘记密码,需要停止mysql进程,并使用下面的命令,使mysql跳过权限方式启动:

# mysqld_safe --user=mysql --skip-grant-tables &

然后输入Mysql,可以直接进入数据库命令行。选择mysql数据库,修改user表里root用户的password:

mysql> use mysql
mysql> update user set password=password('123456') where user='root';
mysql> flush privileges;

最后停止mysql进程,以正常方式启动mysql,可以正常使用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值