Linux安装mysql详细步骤

linux安装mysql详细步骤

最近买了个腾讯云服务器,搭建环境。

该笔记用于系统上未装过mysql的干净系统第一次安装mysql。自己指定安装目录,指定数据文件目录。

linux系统版本: CentOS 7.3 64位

安装源文件版本:mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

mysql安装位置:/software/mysql

数据库文件数据位置:/data/mysql

 

注:未防止混淆,这里都用绝对路径执行命令

        除了文件内容中的#,这里所有带#都是linux命令

  >mysql 是mysql的命令

 

步骤:

1、在根目录下创建文件夹software和数据库数据文件/data/mysql

#mkdir /software/

#mkdir /data/mysql

 

2、上传mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz文件到/software下

 

#cd /software/

#tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

 

3、更改解压缩后的文件夹名称

#mv /software/mysql-5.7.21-linux-glibc2.12-x86_64/  /software/mysql

 

4、创建mysql用户组和mysql用户

#groupadd mysql

#useradd -r -g mysql mysql

 

5、关联myql用户到mysql用户组中

#chown -R mysql:mysql  /software/mysql/

#chown -R mysql:mysql  /data/mysql/

#chown -R mysql  /software/mysql/

#chown -R mysql  /data/mysql

 

6、更改mysql安装文件夹mysql/的权限

#chmod -R 755 /software/mysql/

 

7、安装libaio依赖包,由于我买的腾讯云服务器centos系统自带的有这个依赖包所以不需要安装,不过自带的依赖包会报错,后面介绍解决办法

查询是否暗转libaio依赖包

#yum search libaio

如果没安装,可以用下面命令安装

#yum install libaio

 

8、初始化mysql命令

#cd /software/mysql/bin

#./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize

在执行上面命令时特别要注意一行内容   

[Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck

root@localhost: 后面跟的是mysql数据库登录的临时密码,各人安装生成的临时密码不一样

如果初始化时报错如下:

error while loading shared libraries: libnuma.so.1: cannot open shared objec

是因为libnuma安装的是32位,我们这里需要64位的,执行下面语句就可以解决

#yum install numactl.x86_64

执行完后重新初始化mysql命令

 

9、启动mysql服务

# sh /software/mysql/support-files/mysql.server start

上面启动mysql服务命令是会报错的,因为没有修改mysql的配置文件,报错内容大致如下:

./support-files/mysql.server: line 239: my_print_defaults: command not found
./support-files/mysql.server: line 259: cd: /usr/ local /mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/ local /mysql/bin/mysqld_safe)
 
 
10、修改Mysql配置文件
#vim /software/mysql/support-files/mysql.server
修改前

if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

修改后

if test -z "$basedir"
then
basedir=/software/mysql
bindir=/software/mysql/bin
if test -z "$datadir"
then
datadir=/data/mysql
fi
sbindir=/software/mysql/bin
libexecdir=/software/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi

保存退出

#cp /software/mysql/support-files/mysql.server  /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld

11、修改my.cnf文件

#vi /etc/my.cnf

将下面内容复制替换当前的my.cnf文件中的内容

[client]
no-beep
socket =/software/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/software/mysql
datadir=/data/mysql
port=3306
pid-file=/software/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /software/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

保存退出

 

12、启动mysql

#/etc/init.d/mysqld start

新版本的安装包会报错,错误内容如下:

Starting MySQL.Logging to '/data/mysql/SZY.err'.
2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).

因为新版本的mysql安全启动安装包只认/usr/local/mysql这个路径。

解决办法:

方法1、建立软连接

例 #cd /usr/local/mysql

#ln -s /sofware/mysql/bin/myslqd mysqld

 

方法2、修改mysqld_safe文件(有强迫症的同学建议这种,我用的这种)

# vim /software/mysql/bin/mysqld_safe

将所有的/usr/local/mysql改为/software/mysql

保存退出。(可以将这个文件拷出来再修改然后替换)

 

13、登录mysql

#/software/mysql/bin/mysql -u root –p

 

14、输入临时密码。临时密码就是第8条root@localhost:后面的内容

 

15、修改mysql的登录密码

>mysql   set password=password('root');

>mysql  grant all privileges on *.* to root@'%' identified by 'root';

>mysql flush privileges;

 

16、完成,此时mysql的登录名root  登录密码root

 

 

 

标签: linux, mysql
1
0
« 上一篇: 实用的前端代码
» 下一篇: linux环境搭建前期配置
	</div>
	<div class="postDesc">posted @ <span id="post-date">2018-02-24 11:30</span> <a href="https://www.cnblogs.com/shizhongyang/">如若千夫所指</a> 阅读(<span id="post_view_count">36782</span>) 评论(<span id="post_comment_count">4</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=8464876" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(8464876);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=360816,cb_entryId=8464876,cb_blogApp=currentBlogApp,cb_blogUserGuid='102b7c60-f238-4f43-e63f-08d49c352df2',cb_entryCreatedDate='2018/2/24 11:30:00';loadViewCount(cb_entryId);var cb_postType=1;</script>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#3934736" class="layer">#1楼</a><a name="3934736" id="comment_anchor_3934736"></a>  <span class="comment_date">2018-03-27 13:49</span> <a id="a_comment_author_3934736" href="https://www.cnblogs.com/mr-wuxiansheng/" target="_blank">Mr_伍先生</a> <a href="http://msg.cnblogs.com/send/Mr_%E4%BC%8D%E5%85%88%E7%94%9F" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3934736" class="blog_comment_body">按照你的步骤执行到第13步之后,没有跳出输入密码,提示错误<br><br> ERROR 1045 (28000): Access denied for user 'root'@'localhost'<br><br><br>期待你的回复。。。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3934736,'Digg',this)">支持(1)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3934736,'Bury',this)">反对(0)</a></div><span id="comment_3934736_avatar" style="display:none;">http://pic.cnblogs.com/face/1036837/20170514101520.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#4010976" class="layer">#2楼</a><a name="4010976" id="comment_anchor_4010976"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2018-07-02 18:48</span> <a id="a_comment_author_4010976" href="https://www.cnblogs.com/shizhongyang/" target="_blank">如若千夫所指</a> <a href="http://msg.cnblogs.com/send/%E5%A6%82%E8%8B%A5%E5%8D%83%E5%A4%AB%E6%89%80%E6%8C%87" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_4010976" class="blog_comment_body"><a href="#3934736" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,3934736);">@</a>

Mr_伍先生
输入的密码错了…



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#4073924" class="layer">#3楼</a><a name="4073924" id="comment_anchor_4073924"></a>  <span class="comment_date">2018-09-21 21:23</span> <a id="a_comment_author_4073924" href="https://www.cnblogs.com/Noliebe/" target="_blank">Noliebe</a> <a href="http://msg.cnblogs.com/send/Noliebe" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_4073924" class="blog_comment_body">CentOS 7.3 64位<br>mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz<br>已经安了两天了..绝望了..我还是上包管理器吧.. 谢楼主好意..再见..<br><br>ERROR! <br>The server quit without updating PID file (/var/local/mysql/VM_0_3_centos.pid).</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4073924,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4073924,'Bury',this)">反对(0)</a></div><span id="comment_4073924_avatar" style="display:none;">http://pic.cnblogs.com/face/1284631/20171205174755.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"></span>
			</div>
			<a href="#4097811" class="layer">#4楼</a><a name="4097811" id="comment_anchor_4097811"></a><span id="comment-maxId" style="display:none;">4097811</span><span id="comment-maxDate" style="display:none;">2018/10/24 16:45:57</span>  <span class="comment_date">2018-10-24 16:45</span> <a id="a_comment_author_4097811" href="http://home.cnblogs.com/u/1083309/" target="_blank">Hello-洋洋</a> <a href="http://msg.cnblogs.com/send/Hello-%E6%B4%8B%E6%B4%8B" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_4097811" class="blog_comment_body">老哥,我转载一下</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(4097811,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(4097811,'Bury',this)">反对(0)</a></div>
		</div>
	</div>
<div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
</div><!--end: forFlow -->
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值