Linux环境安装MySQL

本文详细介绍了在Linux系统中安装MySQL的过程,包括下载安装包、创建用户组和用户、设置权限、安装数据库、初始化配置、设置开机启动、启动服务、设定root用户密码以及开放3306端口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在官网下载MySQL安装包 , 然后上传到/usr/local
[root@bogon local]# tar -zxvf mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz
[root@bogon local]# mv mysql-5.5.61-linux-glibc2.12-x86_64 mysql
添加mysql用户组
[root@bogon mysql]# groupadd mysql
添加mysql用户
[root@bogon mysql]# useradd -g mysql mysql
更改mysql目录所属用户组和用户
[root@bogon local]# chown -R mysql:mysql /usr/local/mysql
[root@bogon local]# cd mysql
执行mysql安装脚本
[root@bogon mysql]# ./scripts/mysql_install_db --user=mysql
WARNING: The host 'bogon' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
180914 12:51:06 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180914 12:51:06 [Note] ./bin/mysqld (mysqld 5.5.61) starting as process 6883 ...
OK
Filling help tables...
180914 12:51:07 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180914 12:51:07 [Note] ./bin/mysqld (mysqld 5.5.61) starting as process 6890 ...
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 bogon 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 at http://bugs.mysql.com/

开机启动mysqld服务
[root@bogon mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@bogon mysql]# chkconfig --add mysqld
[root@bogon mysql]# chkconfig --list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off
启动mysqld服务
[root@bogon mysql]# service mysqld start
Starting MySQL.. SUCCESS!
查看mysqld服务状态
[root@bogon mysql]# service mysqld status
 SUCCESS! MySQL running (7175)
建立软链接     
[root@bogon mysql]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/
[root@bogon mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.61 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> exit
[root@bogon mysql]# cd /usr/local/mysql/bin/
设置root用户密码
[root@localhost bin]# ./mysqladmin -u root password '123456'
开放3306端口
[root@localhost bin]# vi /etc/sysconfig/iptables
在 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT的下面添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

[root@localhost bin]# service iptables restart

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值