源码包安装mysql

1.获取mysql源码包

在这里插入图片描述

2.解压安装包

tar -zxf mysql-boost-5.7.17.tar.gz 

在这里插入图片描述
解压后出现目录

3.安装依赖包,解决依赖性

yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
yum install -y ncurses*
yum install gcc gcc-c++ -y
yum install -y bison

这里要注意的是cmake的版本不能太低。

4.进入安装目录安装mysql

mkdir /usr/local/lnmp

创建mysql安装目录

进入解压后的目录
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \	 #安装目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \			 #数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \#Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \						 #安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \						 #安装 innodb 存储引擎
-DDEFAULT_CHARSET=utf8 \								 #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \					 #校验字符
-DEXTRA_CHARSETS=all \									 #安装所有扩展字符集
-DWITH_BOOST=boost/boost_1_59_0/
make && make install

在这里插入图片描述
这样就完成安装了。

5.配置mysql

cd /usr/local/lnmp/mysql/support-files
cp my-default.cnf /etc/my.cnf

复制配置文件到/etc下,并重命名

cp mysql.server /etc/init.d/mysqld

添加启动脚本

vim /etc/my.cnf

在这里插入图片描述
修改配置文件

groupadd mysql -g 27
useradd -u 27 -g 27 mysql

在这里插入图片描述
创建mysql用户组以及用户

 chown root.mysql /usr/local/lnmp/mysql -R

修改目录权限

vim ~/.bash_profile 

在这里插入图片描述

source ~/.bash_profile

修改环境变量,并重新加载。

mysqld --user=mysql --initialize

在这里插入图片描述
初始化mysql,初始化root的密码就在最后一行。

chown mysql /usr/local/lnmp/mysql/data/ -R

修改生成data目录的权限。
如果需要重新初始化,则要删除生成的data目录中的文件。

/etc/init.d/mysqld start

开启mysql

mysql -p

在这里插入图片描述
查看是否能登陆,密码是前面的初始化密码。

mysql_secure_installation 
Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
[root@server4 support-files]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: NO)
[root@server4 support-files]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: No
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : 

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
All done! 

进行认证,修改mysql的root密码。
在这里插入图片描述输入密码后重新登陆。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以按照以下步骤在CentOS 7上通过源码安装MySQL: 1. 首先,确保你的系统已经安装了必要的依赖项。使用以下命令安装依赖项: ``` sudo yum install -y gcc-c++ cmake make bison-devel ncurses-devel ``` 2. 下载MySQL源码。你可以从MySQL官方网站下载最新的源码,例如版本8.0.26: ``` wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26.tar.gz ``` 3. 解压源码: ``` tar -zxvf mysql-8.0.26.tar.gz ``` 4. 进入解压后的目录: ``` cd mysql-8.0.26 ``` 5. 创建一个用于构建MySQL的目录: ``` mkdir build cd build ``` 6. 运行cmake命令以配置MySQL的构建过程: ``` cmake .. ``` 7. 运行make命令以编译MySQL: ``` make ``` 8. 安装MySQL: ``` sudo make install ``` 9. 创建一个用于存储MySQL数据的目录: ``` sudo mkdir /var/lib/mysql ``` 10. 设置MySQL的数据目录的所有者为mysql用户: ``` sudo chown mysql:mysql /var/lib/mysql ``` 11. 初始化MySQL数据库: ``` sudo /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql ``` 12. 启动MySQL服务: ``` sudo /usr/local/mysql/bin/mysqld_safe --user=mysql & ``` 13. 最后,设置MySQL开机自启: ``` sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql sudo chkconfig mysql on ``` 现在,你已经成功通过源码安装MySQL。你可以使用以下命令登录到MySQL: ``` /usr/local/mysql/bin/mysql -u root ``` 记得替换掉`/usr/local/mysql/bin/mysql`为你的实际MySQL安装路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值