文章目录
1. 新建用户及用户组
# 新建用户
$ sudo groupadd mysql
# 新建用户组
$ sudo useradd mysql -s /sbin/nologin -M -g mysql
# 建立安装目录:
$ sudo mkdir /usr/local/mysql -pv
$ sudo chown -R mysql. /usr/local/mysql
除常规编译工具还需要cmake
$ sudo apt-get install cmake
2. 编译安装mysql
$ wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.62.tar.gz
$ tar -zxf mysql-5.5.62.tar.gz
$ cd mysql-5.5.62
$ cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock
报错:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:118 (FIND_CURSES)
cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE)
CMakeLists.txt:354 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
See also "/tmp/mysql-5.5.44/CMakeFiles/CMakeOutput.log".
See also "/tmp/mysql-5.5.44/CMakeFiles/CMakeError.log".
大意是:缺少CURSES_LIBRARY CURSES_INCLUDE_PATH
,无法找到Curses library ,请安装适当的包,移除CMakeCache.txt
并重新运行cmake
,在Debian/Ubuntu上,包名为libncurses5-dev
,在Redhat 和derivates上包名为ncurses-devel
。
3. 安装libncurses5-dev
:
$ sudo apt-get install libncurses5-dev
重新运行cmake那一步
#编译
$ make -j 4
$ sudo make install
$ echo $?
如果输出0则表示安装成功!
4. 配置
$ sudo chown mysql. /usr/local/mysql/data/my.cnf
$ sudo vim /usr/local/mysql/data/my.cnf
加入有中文注释的参数
[mysqld]
port = 3306
datadir = /usr/local/mysql/data/ #数据目录
basedir = /usr/local/mysql/ #程序目录
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
log-bin=mysql-bin #二进制日志,主从复制用
binlog_format=mixed #混合模式复制(mixed-based replication,
server-id = 1 #多服务器时,区分mysql服务器身份的ID
$ sudo ./scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql
5. 初始化mysql:
$ cd /usr/local/mysql/
$ sudo ./scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql
出现一下提示,说明成功
Installing MySQL system tables...
190226 2:57:49 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
190226 2:57:49 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.5.62) starting as process 47300 ...
OK
Filling help tables...
190226 2:57:49 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
190226 2:57:49 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.5.62) starting as process 47306 ...
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:
/usr/local/mysql//bin/mysqladmin -u root password 'new-password'
/usr/local/mysql//bin/mysqladmin -u root -h chen password 'new-password'
Alternatively you can run:
/usr/local/mysql//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 /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
6. 添加为系统服务:
$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
$ chmod +x /etc/init.d/mysqld
$ sudo update-rc.d mysqld defaults
之后你可以这样操作
$ sudo service mysqld start/restart/stop/status
7. 设置密码及登录
$ sudo ln -s /usr/local/mysql/bin/mysql /bin/mysql
$ /usr/local/mysql/bin/mysqladmin -uroot password '123456'
# 登录
$ mysql -uroot -p 123456