1、这里我将Mysql安装在/usr/local/mysql目录里面,也可以安装在其他地方;

mkdir /usr/local/mysql

2、到MySQL官网下载安装包

Linux 下安装mysql 服务这个是我下载的

3、解压并复制

tar -zxvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-Linux-glibc2.5-x86_64/* /usr/local/mysql/

4、创建data目录

mkdir /usr/local/mysql/data

5、创建mysql用户组及其用户

groupadd mysql
useradd -r -g mysql mysql

如果已经存在,没关系,不影响安装

6、初始化数据

[[email protected] mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

7、复制配置文件到 /etc/my.cnf

cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y) 

我安装的没有my-default.cnf,我从别的地方复制到这里一个

8、MySQL的服务脚本放到系统服务中

cp -a ./support-files/mysql.server /etc/init.d/mysqld
修改my.cnf文件
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock //此处因为在我之前有人在测试环境安装过mysql,所以不知道为什么这个地址,我写/var/lib/mysql.sock才好使
character-set-server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

9、创建In

ln -s /usr/local/mysql/  /usr/bin/

10、启动服务

service mysqld start 

11、初始化密码

mysql5.7会生成一个初始化密码,在root中.mysql_secret文件中。

[[email protected] ~]# cat /root/.mysql_secret
# Password set for user '[email protected]' at 2017-03-16 00:52:34 
ws;fmT7yh0CM

12、登录并修改密码 ,如果此处一直报密码输入错误,可以在my.cnf中 写

原创:https://blog.csdn.net/lisongjia123/article/details/57418989

Linux 下安装mysql 服务

可以免密码登录之后:

Linux 下安装mysql 服务

用修改后的密码登录之后,再次登录,再用alter修改密码就可以正常使用了

Linux 下安装mysql 服务


[[email protected] ~]# mysql -u root -p

alter user [email protected] identified by 'tiger';

flush privileges;

13、退出重新登录,完成

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

rows in set (0.11 sec)

原创:https://www.cnblogs.com/xiaotao726/p/6562265.html

Linux 下安装mysql 服务


相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2021-04-20
  • 2021-09-29
  • 2021-10-13
  • 2021-11-06
  • 2021-05-01
  • 2021-10-16
猜你喜欢
  • 2021-11-02
  • 2022-03-01
  • 2022-02-09
  • 2022-01-07
  • 2021-12-21
  • 2021-11-21
  • 2022-01-06
相关资源
相似解决方案