Observation Point

A glimpse at the edge


  • Home

  • Archives

  • Tags

  • Search

Offline install MySQL on CentOS

Posted on 2018-12-01 | In Linux

Offline Install MySQL on CentOS

Install

Recently this problem came across to me: I have to install MySQL Server on a Server (CentOS) with access only to LAN where yum is useless.
Here is the solution I found useful:

Step 1. Download MySQL

Download the package you desire from here as follows..

download_mysql

Step 2. Remove the built-in mariaDB

  1. query the installed packages

rpm -qa | grep -i mariadb
This should print some names.

  1. remove them

rpm -e --nodeps <package_names_listed_above>
Replace <package_names_listed_above> with the names shown with the previous command.

Step 3. Create a New User for MySQL Management (Optional)

  1. Create new accounts/ account groups
1
2
3
4
5
6
# create a new user group called mysql
groupadd mysql
# create a user under mysql group
useradd -g mysql mysql -d /home/mysql
# initialize the password for him
passwd mysql
  1. Create directories for data/log/etc.

The directories shall be consistant with what you configure in my.cnf, which will be created later.

1
2
3
mkdir /home/mysql/3306/data
mkdir /home/mysql/3306/log
mkdir /home/mysql/3306/tmp

Step 4. Upload the software to the server

Move the software to /usr/local, create symbolic link and enable only usr mysql with the access.

1
2
3
4
5
6
7
8
# unzip the package
tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

# create a symbolic link
ln -s mysql-5.7.21-linux-glibc2.12-x86_64 mysql

chown -R mysql:mysql mysql/

Step 5. Create a config file my.cnf

1
2
cd /etc
vi my.cnf

A complete example (also what I am using) of my.cnf will be provided at the end of this blog.

Step 6. Install MySQL

1
2
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql

After this step, a randomly initialized password for root user will be generated in home/mysql/3306/log/error.log, or the directory you specify at my.cnf

Step 7. Setup auto-start service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod +x /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

# check if the service is added successfully
chkconfig --list mysqld

# switch to user:mysql before the next step
su mysql

# start the service
service mysqld start

Step 8. Configure environment variables

1
2
3
4
5
6
7
# make sure you have logged in as mysql
vi ~/.bash_profile

# append this line to the file
export PATH=$PATH:/usr/local/mysql/bin

source ~/.bash_profile

Step 9. Login and reset password

1
2
3
4
5
# input the password generated
mysql -uroot -p

# reset a password friendly to human
set password for root@localhost=password("123456");

Upgrade/uninstall

A method is also provided if you wanna upgrade or unintall the mysql that was installed in this way. Please backup import files before you go.

Step 1. Delete related service

1
2
chkconfig --list | grep -i mysql
chkconfig --del <related service>

Step 2. Empty related directories

1
2
3
rm -rf /home/mysql/3306/data/*
rm -rf /home/mysql/3306/log/*
rm -rf /home/mysql/3306/tmp/*

Step 3. Remove installed software

1
2
3
4
5
6
# you can find where you installed them with these two commands
whereis mysql
find / -name mysql

# get rid of  them
rm -rf /usr/local/mysql

An example for my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[client]                                        
port = 3306                                    
socket = /home/mysql/3306/tmp/mysql.sock                       

[mysqld]                                       
server-id = 1                                  
port = 3306                                    
basedir = /usr/local/mysql                      
datadir = /home/mysql/3306/data                     
tmpdir  = /home/mysql/3306/tmp        
socket = /home/mysql/3306/tmp/mysql.sock        
pid-file = /home/mysql/3306/log/mysql.pid      
skip_name_resolve = 1                          
character-set-server = utf8mb4                  
transaction_isolation = READ-COMMITTED         
collation-server = utf8mb4_general_ci 
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1 
max_connections = 400  
max_connect_errors = 1000 
explicit_defaults_for_timestamp = true 
max_allowed_packet = 128M                
interactive_timeout = 1800               
wait_timeout = 1800                   
tmp_table_size = 16M   
max_heap_table_size = 128M     
query_cache_size = 0      
query_cache_type = 0

read_buffer_size = 2M                      
read_rnd_buffer_size = 8M   
sort_buffer_size = 8M     
binlog_cache_size = 1M    

back_log = 130       

log_error = /home/mysql/3306/log/error.log    
slow_query_log = 1                             
long_query_time = 1                        
slow_query_log_file = /home/mysql/3306/log/slow.log               
log_queries_not_using_indexes = 1              
log_throttle_queries_not_using_indexes = 5     
min_examined_row_limit = 100                    
expire_logs_days = 5                         

log-bin = mysql-bin                          
binlog_format = ROW                           
binlog_row_image = minimal                  

innodb_open_files = 500                        
innodb_buffer_pool_size = 64M                  
innodb_log_buffer_size = 2M                    
innodb_flush_method = O_DIRECT                  
innodb_write_io_threads = 4                    
innodb_read_io_threads = 4
innodb_lock_wait_timeout = 120                  
innodb_log_file_size = 32M                     
Read more »

Task scheduler - solution & explanation

Posted on 2018-06-26 | In Programming

Task Scheduler

A very interesting leetcode problem came across to me today. The description is attached below. This problem could be solved in a smart and concise way so I would like to share with you: A 5 line C++ code that beats 100% other solutions

Read more »

Understanding Manacher Algorithm

Posted on 2018-06-12 | In programming

Understand Manacher algorithm

Manacher algorithm came across to me recently which solves palindromic substrings finding problem in an efficient way. The code could be really simple (few lines) whereas the idea behind manacher is kinda complex. This article tries to walk you through the basic intuition of Manacher algorithm and how it works.

Problem description

This problem is a great for better understanding manacher algorithm:

Given a string, your task is to count how many palindromic substrings in this string.

The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.

The problem isn’t complicated. We need to find the number of substrings that are palindromic. Let’s start by looking at a straight forward approach.

Read more »

An introduction to bitset

Posted on 2018-06-06 | In Programming

bitset

According to cpp official reference

The class template bitset represents a fixed-size sequence of N bits. Bitsets can be manipulated by standard logic operators and converted to and from strings and integers.

Bitset is a powerful tool dealing with ordered binary series, i.e. an array containing either 1 or 0.

Read more »

How to free up /boot

Posted on 2018-05-06 | In Linux

Sometimes it gives a error saying no enough space left when I try to install some new packages which causes dependency problem preventing kernels from being properly configured. Later I found old kernels could take up significant amount of space if you don’t clean up regularly.

Here is a simple solution to tackle this problem.

1
2
3
4
5
6
7
8
9
10
11
12
# Check the availability of each disk
sudo fdisk -l
df -h

# Check the kernel you are currently on
uname -r

# List all the old kernels available to delete
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]'

# Delete them manually
sudo dpkg --purge <results_shown_in_previous_command>
Read more »

Closure in Python by examples

Posted on 2018-04-12 | In Programming

Overview

  1. Closure is an important feature of Python which protect the variables defined in different places against poisoning each other.
  2. An common usage of closure is defining an function within another function. The variables are thus defined in different scope, some covering others. So the tricks and traps with closure is talking about how can we make it convenient by using this features and avoid faults that could be caused by it.
  3. Closure could directly use variables defined outside of it and within the scope surrounding it. When it looks for an variable, it starts searching from local variables. When there is no local variables with the same name existed, it extends the searching space to the closure surrounding it.
  4. Using variables and assigning new values to variables are different. When it tries assign an value to a variable, it starts from local variables as well but it would create a local copy of it if the target doesn’t exist.

We will walk through these issues with some examples.

Read more »

CUDA kick-start

Posted on 2018-04-11 | In Programming
  • How CUDA works

CUDA accelerates computations following a single instruction multiple thread (SIMT) parallelism pattern.

CUDA GPU has multiple cores (threads) containing one ALU and one FPU (which are not important here). A streaming Multiprocessor (SM) has multiple cores.

By saying SIMT, CUDA breaks down a computation (one instruction) into several

  • CUDA API & C extension
Read more »

Intro to Pandas

Posted on 2018-04-01 | In Data engineering

Data pre-processing

  • Threshold values into 0/1
1
2
3
4
5
import pandas as pd

a = pd.Series([1,3,5,6,3,4,1,2,0,4])
b = Series(a>3).astype(int)
print(b)
Read more »

Where to put const in C++

Posted on 2018-03-15 | In Programming

Problem

Pointer in C++ is confusing. The declaration of pointer makes it worser.
One classic problem of pointer declaration is as follows.

1
2
const int * p1;   // Case 1;  
int * const p2;   // Case 2; Initialization required in practice

So here are the problems:

  1. What’s the difference between this two statements?
  2. What does const constrains on each of them?
Read more »

Why cross-validation

Posted on 2018-02-25 | In Machine Learning

TL; DR

  • Cross-validation (CV), or k-fold CV is a model evaluation method, which is extensively used for fine-tuning models.
  • Advantages:
    1. Make full use of data;
    2. Prevent overfitting1;
    3. Estimation on variance of model when applied to real data;
  • Disadvantages:
    1. Computational Expensive;
  • Only splitting the whole data set into training/test set may cause overfitting.
  • Implementation:
    1. Split the whole data set into one training set and one test set;
    2. Split the training set into k parts;
    3. Repeat the experiments k times. Each time:
      1. One different part of data are held out and used as validation set;
      2. Train the model with the rest k-1 parts of data;
      3. Validate the model on validation set and got one result;
    4. (optional) Average the total k results.
Read more »

Python tricks & traps

Posted on 2018-02-17 | In Programming

In this article I list out some tricks in Python programming. I will keep updating this post each time I find anything interesting.

Traps in default value

1
2
3
4
5
6
7
8
9
10
11
def append_list(num, res=[]):
  res.append_list(num)
  return res

l1 = append_list(1)
l2 = append_list(2)
l3 = append_list(3)

print(l1)
print(l2)
print(l3)

The code seem fine because every time the function itself would initialize an empty list and append a new value to it. However the result is very surprising:

1
2
3
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]

This is because the default value, which is an empty list here keeps using the same address in the memory. Whenever value is specified for res, it simply use that same list on the specific memory address. These three list, l1, l2 and l3 are thus actually manipulating the same list.

The correct way to do this is as follows, which would kinda avoid this problem.

1
2
3
4
5
6
7
8
def append_list(num, res=None):
    if res == None:

l3 = append_list(3)

print(l1)
print(l2)
print(l3)
Read more »

Decorator in 10 minutes

Posted on 2018-02-06 | In Programming

本文正文在 2025 年 5 月仓库被上游覆盖时丢失,互联网档案馆只保留了页面外壳。链接保留在此,正文待重写。

Read more »
Eric Wan

Eric Wan

A glimpse at the edge

12 posts
5 categories
14 tags
RSS
GitHub LinkedIn
© 2018 - 2026 Eric Wan
Powered by Jekyll
Theme - NexT.Pisces