龙空技术网

linux下Mysql安装

虫儿飞啊飞啊飞 113

前言:

现在咱们对“linuxmysql修改端口号”大约比较重视,你们都需要学习一些“linuxmysql修改端口号”的相关文章。那么小编在网摘上收集了一些对于“linuxmysql修改端口号””的相关资讯,希望各位老铁们能喜欢,姐妹们快快来了解一下吧!

1、安装

查看有没有安装过:

yum list installed mysql*

rpm -qa | grep mysql*

查看有没有安装包:

yum list mysql*

安装mysql客户端:

yum install mysql

安装mysql 服务器端:

yum install mysql-server 在centOs7 中未找到

yum install mysql-devel

2、启动 && 停止

数据库字符集设置yuyum

mysql配置文件/etc/my.cnf中加入default-character-set=utf8

启动mysql服务:

service mysqld start或者/etc/init.d/mysqld start开机启动:

chkconfig -add mysqld,查看开机启动设置是否成功chkconfig --list | grep mysql*

mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

停止:

service mysqld stop

3、登录

创建root管理员: mysqladmin -u root password 123456

登录: mysql -u root -p输入密码即可。

忘记密码: service mysqld stop

mysqld_safe --user=root --skip-grant-tables

mysql -u root

use mysql

update user set password=password("new_pass") where user="root";

flush privileges;

4、远程访问

开放防火墙的端口号

mysql增加权限:mysql库中的user表新增一条记录host为“%”,user为“root”。

5、Linux MySQL的几个重要目录

数据库目录: /var/lib/mysql/

配置文件: /usr/share /mysql(mysql.server命令及配置文件)

相关命令: /usr/bin(mysqladmin mysqldump等命令)

启动脚本: /etc/rc.d/init.d/(启动脚本文件mysql的目录)

2.解压并复制

tar -xvf mysql-5.7.17-linux-glibc2.5-i686.tar.gzmv mysql-5.7.17-linux-glibc2.5-i686.tar.gz/* /usr/local/mysql/

3.创建data目录(很重要!) /usr/local/data/mysql-5.7.21

/usr/local/mysql/data

4.创建mysql用户和修改权限

groupadd mysql

useradd -g mysql -d /home/mysql -s /bin/bash mysql

chown -R mysql:mysql /usr/local/mysql

5.初始化数据

./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir= /usr/local/mysql/data

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

cp -a ./support-files/my-default.cnf /etc/my.cnf

mysql的服务脚本放到系统服务中

cp -a ./support-files/mysql.server /etc/init.d/mysqld

修改my.cnf文件 (vim /etc/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

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

8.启动mysql

service mysqld start

ps -ef #查看是启动

ps -ef | grep mysql

连接:格式: mysql -h主机地址 -u用户名 -p用户密码

mysql –u root -p

10.修改密码

set password=password('123456');

3、退出MYSQL命令

exit (回车)

FAQERROR! The server quit without updating PID file (/usr/local/mysql/data/linux1.pid).

可能是mysql未正常关闭,系统表损坏

在/etc/my.cnf加上

myisam_recover_options=force,backup

初始化:

./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir= /usr/local/mysql/data

报错

[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

2018-09-04 15:45:47 [ERROR] The data directory needs to be specified.

mysqld –initialize

执行mysqld –initialize

报错bash: mysqld: 未找到命令...

一般是环境变量中未加

连接:

mysql –u root -p

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

因为初始化时会随机生成一个密码

如果没注意,可以在日志中找

grep "password" ./data/mariadb.log

标签: #linuxmysql修改端口号